Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How to determine when a browser window is closing in Internet Explorer 7


View products that this article applies to.

Introduction

This article describes how to determine when a browser window is closing in Windows Internet Explorer 7. This behavior differs from the behavior that occurs when a Web page is refreshed. This behavior also differs from the behavior that occurs when a URL is visited from another Web page.

↑ Back to the top


More information

Window properties such as the window.screenTop property and the window.screenLeft property do not work in Windows Internet Explorer 7. This behavior differs from the behavior of Microsoft Internet Explorer 6.

For example, in Internet Explorer 7, the following code does not cause a message to appear when you close a browser window:
<html> 
<script>
function closeHandler() {
if (window.screenTop > 9000 && window.screenLeft > 9000) {
alert("The window will be closed");
}
} 
window.onunload = closeHandler;
</script> 
<body>
Test page
</body> 
</html>
To determine when the browser window is closing, use any of the following methods:
  • Use a modal dialog box as the main window.
  • Use a parent frameset. Use the onunload event of the parent frameset to determine when the browser window closes.

↑ Back to the top


Keywords: KB934367, kbtshoot, kbwebbrowser, kbinfo

↑ Back to the top

Article Info
Article ID : 934367
Revision : 2
Created on : 7/29/2009
Published on : 7/29/2009
Exists online : False
Views : 413