Does anyone know how to detect if a browser is closed by a user clicking the "x" or by going to the File->Close menu option? I need major help on this real quick. Thanks in advance!
I use this to trap the closing of a browser.
Place in <head></head> In my application of the code I use a hidden field to detect changes.
Hope this helps
<!-- Code to trap user from clicking the upper right 'X' to quit -->
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
function window_onbeforeunload() {
// Check your flag to determine if changes have been made
if (parent.document.frames(0).document.forms(0).hdnDirty.value > 0 ) {
event.returnValue = "You have made changes that have not be saved.\nIf you want to save changes click 'Cancel' and then click 'Save'.\nTo discard changes click ok."; }
}
</SCRIPT>
<!-- Event to fire when "X" is clicked -->
<SCRIPT LANGUAGE=javascript FOR=window EVENT=onbeforeunload>
<!--
window_onbeforeunload()
//-->
</SCRIPT>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.