Skip to content Skip to sidebar Skip to footer

Show A Message Box When User Close IE

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 i

Solution 1:

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;

Solution 2:


Solution 3:

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()"

Solution 4:

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.


Post a Comment for "Show A Message Box When User Close IE"