Consider the scenario where you wish to prevent other websites from embedding your site within an
/* break us out of any containing iframes */ if (top != self) { top.location.replace(self.location.href); }
While effective, this code can be bypassed by a frame-busting buster:
<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://example.org/page-which-responds-with-204' } }, 1) </script>
This buster operates by:
So, how do you defeat the frame-busting buster?
One effective approach is to use the X-Frame-Options: deny directive, supported by most modern browsers. This directive prevents framing even when scripting is disabled:
X-Frame-Options: deny
Browser Support:
Firefox (3.6.9):
Chrome/Webkit:
The above is the detailed content of How Can I Defeat a Frame-Busting Buster That Bypasses Traditional Frame-Busting JavaScript?. For more information, please follow other related articles on the PHP Chinese website!