JavaScript中的反iFrame Buster
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript中的反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.
var prevent_bust = 0; window.onbeforeunload = function() { prevent_bust++; } setInterval(function() { if (prevent_bust > 0) { prevent_bust -= 2; window.top.location = 'http://domain.com'; } }, 1); </script>
以上是关于JavaScript中的反iFrame Buster的主要内容,如果未能解决你的问题,请参考以下文章
java 和 JS(javaScript)中的反斜杠正则转义
javascript-如何检测 iframe 中的滚动事件?
如何防止 iFrame 中的 JavaScript 访问外部站点的属性,即使 iFrame 的内容来自同一来源?