JavaScript   发布时间:2022-04-16  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了js实现防止被iframe的方法大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

本文实例讲述了js实现防止被iframe的方法。分享给大家供大家参。具体如下:

方法一:

// Break out of an iframe,if someone shoves your site // into one of those silly top-bar URL shortener things. // // Passing `this` and re-aliasing as `window` ensures // that the window object hasn't been overwritten. // // Example: // var window = 'haha,punked!'; // // Note: Probably unnecessary,but just for kicks. (function(window) { if (window.LOCATIOn !== window.top.LOCATIOn) { window.top.LOCATIOn = window.LOCATIOn; } })(this);

方法二:

// A more cryptic one-liner,to awe & impress. // // No need to protect `window` since `this` is // immutable,and at the topmost level means // `window` anyways. Here,we compare LOCATIOns // on the left side of the "&&" and execute the // code in parenthesis if that condition is // true (top LOCATIOn isn't iframe LOCATIOn). // // Otherwise,nothing happens. It's basically an // if statement without wrapping curly brackets. // // Weird,I know. But pretty cool,right? :) this.top.LOCATIOn !== this.LOCATIOn && (this.top.LOCATIOn = this.LOCATIOn);

希望本文所述对大家的javascript程序设计有所帮助。

大佬总结

以上是大佬教程为你收集整理的js实现防止被iframe的方法全部内容,希望文章能够帮你解决js实现防止被iframe的方法所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:js防止