Note that there are some explanatory texts on larger screens.

plurals
  1. POFrame Busting buster not completely working for IE
    primarykey
    data
    text
    <p>I've been working on a Frame busting buster (what's in a name, hehe), which kept my users on my page and open a new window with the target URL. I'm using a Lightbox script to display iframes, this is what I'm doing:</p> <p>1) Added an event for all .lightbox clicks, f.e:</p> <pre><code>$('.lightbox').live("click", function(e) { e.preventDefault(); $('#redirectURL').val($(this).attr('href')); $(this).lightbox(); } </code></pre> <p>2) Added a frame busting buster:</p> <pre><code>&lt;script type="text/javascript"&gt; var prevent_bust = 0 window.onbeforeunload = function() { prevent_bust++ } setInterval(function() { if (prevent_bust &gt; 0) { prevent_bust -= 2 window.top.location = 'http://server-which-responds-with-204.com' } }, 1) &lt;/script&gt; </code></pre> <p>3) Modified the frame busting buster code to fit my needs, which are:</p> <ul> <li>detect if an iframe wants to change the window.top.location</li> <li>if so, prevent this from happening using the 204 server respond</li> <li>open a new page: <code>window.open( $('#redirectURL', '_blank' );</code></li> <li>close lightbox: <code>$('.jquery-lightbox-button-close').click();</code></li> </ul> <p>So far, this is what I've come up with:</p> <pre><code>var prevent_bust = 0 window.onbeforeunload = function() { prevent_bust++ } setInterval(function() { if (prevent_bust &gt; 0) { prevent_bust -= 2; redirectURL = $('#redirectURL').val(); if(redirectURL != "") { window.top.location = 'http://www.****.com/ajax/nocontent.php'; window.open(redirectURL, "_blank"); $('.jquery-lightbox-button-close').click(); $('#redirectURL').val(''); } else { window.top.location = 'http://www.****.com/ajax/nocontent.php'; } } }, 1); </code></pre> <p>// EDIT: <code>Before I forget, 'nocontent.php' is a file that returns a 204 header</code></p> <p>For Firefox it acts as I programmed it, if there's a change detected in the window.top.location it opens a new frame/page and prevents the iframe from reloading the top location and to round it up, it closes the jQuery lightbox.</p> <p>Safari/Chrome act similar, they open a new browser screen (<code>not sure if theres an option to say target="_newtab" or something?</code>). Only bad thing is they do not really display a message of the popup is blocked, but I can work around that by displaying a popup balloon on my website with a link to the page.</p> <p>Internet Explorer is, what a shocker, the only black sheep left.. IE does not open a new popup, nor blocks the window.top.location reset by the iFrame and simply continues refreshing the complete page to the '#targetURL'. It does the same with the default busting code.. so it's not because of some of my edits.</p> <p>Anyone who is able to spot a mistake in my code?</p> <p>Also, I would need a little modification that sees if the request has been made by an iframe or by the user itself, because now there is really NO option for a user to leave my page by changing the address in the toolbar or by clicking a link, which is not really needed LOL.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload