Anti Iframe Buster by Lex Johnson | JavaScriptSource

Anti Iframe Buster by Lex Johnson

Lex Johnson Jul 4, 2012


Like using iframes on your site but worried about people using javascript to bust out of them? Use this code to bust the busters!


iframes are a necessary evil for many of us. Putting a third party site in an iframe is always a risk because they can break out of that iframe and redirect the visitor. This code acts as a defense and prevents them from being able to bust out of the iframe.

Code Snippet

<script type="text/javascript">
    var prevent_bust = 0  
    window.onbeforeunload = function() { prevent_bust++ }  
    setInterval(function() {  
      if (prevent_bust > 0) {  
        prevent_bust -= 2  = ''  
    }, 1)  

Leave a Response

(1 comment)

Hi, Have you ever tested this. Is that works for you. Solution not working for me. What does mean.

Gowri Jul 5, 2013