iFrame redirect killer works 1/8th the time (Safari)

Hey guys,

I am displaying an external website via an iFrame on my website. I am using the following code to detect if the iFrame tries to redirect the parent window:


<body>
<script type="text/javascript">
	var framekiller = true;
	window.onbeforeunload = function() { 
	if(framekiller) {
		return "Stay on this page or leave the page to follow the URL.";
	}
};
</script>

<iframe id="page" style="height:400px;width:100%;border:0px solid black;" src="'.$safe_url.'">Hello</iframe>
	
	<script type="text/javascript">
		document.getElementById("page").onload = function() { 
		framekiller = false;
		};
 	</script>
</body>

This works 100% of the time in Firefox. It notifies me that the page is trying to redirect, and lets me choose to stay or follow the redirection.

Now in Safari this seems to work about 1 every 8 times, or less. Can someone please help me understand why this happens and tell me how I can fix it?

Also, in Firefox it appears I can’t display text within the redirection box warning, but in Safari (when it works) I can. Any idea why?

Thanks very much, you guys are always helpful.

I have two doubts
First one:

What does the “return” line? i mean, it actually displays something? i would use a “return confirm(“text here”);” instead.

Second:

In relation with the first doubt, how do you choose to stay or leave?

See you :cool:

That doesn’t answer my question, but I will answer your questions.

  1. You can’t create your own confirm dialog box when this standard redirection dialog pops up. You can only return text to appear in between the default text (the default text is determined by the browser).

  2. The dialog comes up with two buttons… You pick one of them.

Anyone else?