Microsoft KB Archive/934367

From BetaArchive Wiki
Knowledge Base


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

Article ID: 934367

Article Last Modified on 10/27/2007



APPLIES TO

  • Windows Internet Explorer 7



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.

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.
  • Use a WebBrowser control in the application to host the Web pages. You can use the WebBrowser control events to determine when the browser window closes.


Keywords: kbinfo kbtshoot kbwebbrowser KB934367