Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1791 How can I detect the browser close event?

irt.org | Knowledge Base | JavaScript | Window | Q1791 [ previous next ]

Q1791 How can I detect the browser close event?

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

Feedback on 'Q1791 How can I detect the browser close event?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.