Posted By

apphp-snippets on 11/04/15


Tagged

iframe javascript


Versions (?)

Anti iFrame Buster in JavaScript


 / Published in: JavaScript
 

URL: www.apphp.com/index.php?snippet=javascript-anti-iframe-buster

You know that iFrames are a necessary evil for many of us. When yuo put a third party site in an iframe is always a risk because they can break out of that iframe and redirect the visitor to another location. This code acts as a defense for such cases and prevents them from being able to bust out of the iframe.

  1. <script type="text/javascript">
  2. var prevent_bust = 0;
  3. window.onbeforeunload = function() { prevent_bust++; }
  4. setInterval(function() {
  5. if (prevent_bust > 0) {
  6. prevent_bust -= 2;
  7. window.top.location = 'http://domain.com';
  8. }
  9. }, 1);
  10. </script>

Report this snippet  

You need to login to post a comment.