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

Need iframe to change onbeforeunload function of parent window 1

Status
Not open for further replies.

tcstom

Programmer
Aug 22, 2003
235
GB
I have an iframe which, in certain circumstances, needs to nullify the onbeforeunload event of its parent window. I thought I could just use
Code:
window.parent.onbeforeunload = null;
but this doesn't seem to work. Can anyone help? Before anyone gets huffy about the use of frames and IE-only events, I have my reasons!
 
Hi

Well, it is not standard, but [tt]onbeforeunload[/tt] works in Mozillas and Safari too. Regarding the reseting of [tt]onbeforeunload[/tt], seems to work only in Mozillas and Safari. At least for me.

I suggest to use a flag as a workaround.
Code:
<html>
<head>
<title>A</title>
</head>
<body>
<script type="text/javascript">
[red]var doit=true;[/red]
window.onbeforeunload=function(){[red]if(doit)[/red]alert('Bye')}
</script>
<iframe src="b.htm">
</body>
</html>
Code:
<html>
<head>
<title>B</title>
</head>
<body>
<script type="text/javascript">
[red]window.parent.doit=false;[/red]
</script>
</body>
</html>

Feherke.
 
Nice idea! Thanks, that works lovely. Have a star.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top