Closing a help window when the main window closes
This demo shows how to close a help page when a web-based application's window is closed.
How to see the demo
Click here to open the help window: open help window. Then, close this window.
Code
<script>
function opener() {
helpWindow = window.open('apage.htm','windowname','width=300,height=200');
}
</script>
<body onUnload="if ((helpWindow) && !(helpWindow.closed)) helpWindow.close()">
How it works
This script uses the onUnload event to detect that the user is closing the window. It then checks to see if the help window is open and closes it if it's open. The script names the help window "helpWindow," so the onUnload event checks for this window by name. It will not close other open windows.
Browser compatibility
This script should work in any browser.
Questions?
Just send us an email.