I am working on a busting buster frame (called hehe) that left my users on my page and opened a new window with the destination URL. I am using a Lightbox script to display iframes, this is what I am doing:
1) Added event for all clicks .lightbox, fe:
$('.lightbox').live("click", function(e) { e.preventDefault(); $('#redirectURL').val($(this).attr('href')); $(this).lightbox(); }
2) Added frame break separator:
<script type="text/javascript"> var prevent_bust = 0 window.onbeforeunload = function() { prevent_bust++ } setInterval(function() { if (prevent_bust > 0) { prevent_bust -= 2 window.top.location = 'http://server-which-responds-with-204.com' } }, 1) </script>
3) A modified frame breakdown code that fits my needs:
- determine if iframe wants to change window.top.location
- if so, prevent this using server 204 response
- open a new page:
window.open( $('#redirectURL', '_blank' );
- close lightbox:
$('.jquery-lightbox-button-close').click();
So far this is what I came up with:
var prevent_bust = 0 window.onbeforeunload = function() { prevent_bust++ } setInterval(function() { if (prevent_bust > 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);
// EDIT: Before I forget, 'nocontent.php' is a file that returns a 204 header
For Firefox, it works when I programmed it, if a change is detected in the window.top.location window, it opens a new frame / page and does not allow the iframe to reload the top location and round it, it closes the jQuery illuminator.
Safari / Chrome works similarly, they open a new browser screen ( not sure if theres an option to say target="_newtab" or something?
). The only bad thing is that they donβt actually display a pop-up message, itβs blocked, but I can get around this by showing a pop-up on my site with a link to the page.
Internet Explorer is what a shocker is, the only black sheep. IE does not open a new popup and does not block window.top.location reset iFrame and just continues to refresh the full page to "#targetURL. It does the same with the default busting code .. so it is not due to some of my changes.
Anyone who can spot an error in my code?
In addition, I will need a small modification that will see if the request was processed by the iframe or by the user himself, because now the user has no way to disable my page by changing the address on the toolbar or by clicking on the link that LOL does not need.
Thanks in advance.