Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect if a browser is closed

Status
Not open for further replies.

WildWest

Programmer
Apr 2, 2002
111
US
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!

WildWest
 
<body onbeforeunload=&quot;Stop(this)&quot;>

<script language=javascript>
function Stop(theField){
event.returnValue = &quot;My Description.&quot;;

}
</script>
 
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 = &quot;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.&quot;; }
}
</SCRIPT>
<!-- Event to fire when &quot;X&quot; is clicked -->
<SCRIPT LANGUAGE=javascript FOR=window EVENT=onbeforeunload>
<!--
window_onbeforeunload()
//-->
</SCRIPT>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top