SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code:
    <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.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Location
    Bs. As. - Argentina
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have two doubts
    First one:
    Quote Originally Posted by svcghost View Post
    ...
    Code:
    <script type="text/javascript">
    ...
    		return "Stay on this page or leave the page to follow the URL.";
    ...
    </script>
    What does the "return" line? i mean, it actually displays something? i would use a "return confirm("text here");" instead.

    Second:
    Quote Originally Posted by svcghost View Post
    ...
    ... It notifies me that the page is trying to redirect, and lets me choose to stay or follow the redirection...
    In relation with the first doubt, how do you choose to stay or leave?


    See you

  3. #3
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Addict svcghost's Avatar
    Join Date
    Oct 2010
    Posts
    288
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone else?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •