Javascript 如何防止iframe自身统一
我们使用iFrame展示网站的设计(征得他们的同意)。问题是,有些网站有如下脚本:Javascript 如何防止iframe自身统一,javascript,jquery,Javascript,Jquery,我们使用iFrame展示网站的设计(征得他们的同意)。问题是,有些网站有如下脚本: if (top != self) top.location.replace(self.location.href); 这会导致浏览器“跳转”到其网站。我们如何抑制这些脚本?有办法吗 在上找到: var prevent_bust = 0; // Event handler to catch execution of the busting script. window.onbeforeunload = fun
if (top != self) top.location.replace(self.location.href);
这会导致浏览器“跳转”到其网站。我们如何抑制这些脚本?有办法吗 在上找到:
var prevent_bust = 0;
// Event handler to catch execution of the busting script.
window.onbeforeunload = function() { prevent_bust++ };
// Continuously monitor whether busting script has fired.
setInterval(function() {
if (prevent_bust > 0) { // Yes: it has fired.
prevent_bust -= 2; // Avoid further action.
// Get a 'No Content' status which keeps us on the same page.
window.top.location = 'http://server-which-responds-with-204.example.com/';
}
}, 1);
这似乎是最可靠的方法,但你必须使用它,看看你的情况是否适合,然后在这里报告。祝你好运
PS-如果你想做更多的研究,该页面上还有其他内容。相关的(可能会有答案,请参阅“事实证明,你的框架破坏代码可以被破坏…”),称为框架破坏程序。据说有一些能破镜重圆的东西。请看:(但是,我想问,如果你得到了网站的同意,那么他们为什么要使用frame Buster?@Pekka웃 - 原来还有一个叫汤姆的-