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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Canceling the onbeforeunload event

Status
Not open for further replies.
Joined
Jun 19, 2001
Messages
86
Location
US
I have a window that spawns a child window that contains a java applet. When the user closes the child I need to be sure that the parent was closed first. I've tried the following:

<SCRIPT LANGUAGE=&quot;JavaScript1.2&quot; TYPE=&quot;text/javascript&quot;>
<!-- Hide
window.onbeforeunload = unloadFunc;

function unloadFunc()
{
if(self.opener.closed) {
mess = &quot;&quot;
return mess;
} else {
alert('You must close the other window first!');
window.onbeforeunload = null;
}
}
// unhide -->
</SCRIPT>

The only problem is that it gives the alert but the window closes anyway. I need a way of aborting the onbeforeunload event until the parent window has been closed.
 
try the following:

in between your <head></head> tags write:

<script language=javascript>
function unloadFunc()
{
if(!self.opener.closed) {
event.returnValue = &quot;must close the other window first!&quot;;
}

}
</script>

....

<body ... onbeforeunload=&quot;unloadFunc()&quot;>
 
I think you may need to change
window.onbeforeunload = null; to
return false;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top