You are here: irt.org | FAQ | JavaScript | Window | Q1791 [ previous next ]
Here is something that work for IE4 and up.
In the onUnload event of the html <BODY> tag, call a function that used the mouse position to determine if the browser close button has been click. The clientX and clientY properties retrieves negative values since they excluded window decorations and scroll bars.
<script language="JavaScript"><!— function unloadPage() { if (window.event) { if (window.event.clientX < 0 && window.event.clientY < 0) { // do something alert('Detecting browser close event'); } } window.self.close; } //--></script> <body class="Plain" onUnload="unloadPage()">
Submitted by CGagnon