show a message box when user close IE

2019-07-04 01:17发布

Any javascript to prompt a message box when a user closes IE? I have tried to find a code sample for quite a while but failed.

thanks in advance, George

Here is my html code, but it has the following error. Any ideas?

To help protect your security, Internet Explorer has restricted this webpage from running scripts or ActiveX controls that could access your computer. Click here for options...

4条回答
Viruses.
2楼-- · 2019-07-04 01:53

You will get unload message during refresh also. Better to check clientx and clientY also in the beforeunload. This is a pseudo code...

<script type="text/javascript">

    var myclose = false;

    function ConfirmClose()
    {
        if (event.clientY < 0)
        {
            event.returnValue = 'Any message you want';

            setTimeout('myclose=false',100);
            myclose=true;
        }
    }

    function HandleOnClose()
    {
        if (myclose==true) alert("Window is closed");
    }
</script> onbeforeunload="ConfirmClose()" onunload="HandleOnClose()"
查看更多
孤傲高冷的网名
3楼-- · 2019-07-04 02:07

You are looking for the beforeunload event.

For example:

function someCloseEvent() {
  return "Any string value here forces a dialog box to \n" +
         "appear before closing the window.";
}

window.onbeforeunload = someCloseEvent;
查看更多
Lonely孤独者°
4楼-- · 2019-07-04 02:10

On a side note, I would seriously consider whether you want to do this. When I close the window, I'm done with your site, I don't want any more messages from you. Popping up an extra window is going to annoy a lot of people.

查看更多
登录 后发表回答