Всплывающее окно на выходе страницы

Я пытаюсь сделать всплывающее окно каждый раз, когда страница закрывается или удаляется. Сейчас у меня есть

<script type="text/javascript">
function box()
{
    var r=confirm("Message");
    if (r==true)
    {
        window.location.href="yes.html";
    }
    else
    {
        window.location.href="no.html";
    }
}
</script>


<body onunload="box();">

У меня есть 2 проблемы с этим:

It only shows the box if you actually navigate away from the page, refresh, new url etc. If you exit the tab or browser, the box doesnt pop up.

No matter what button you press, it just sends you where you tried to go originally, it never sends you to no.html or yes.html.

Может кто-нибудь сказать мне, как это возможно?

Ответы на вопрос(1)

Ваш ответ на вопрос