广

JavaScript

  • IOS开发
  • android开发
  • PHP编程
  • JavaScript
  • ASP.NET
  • ASP编程
  • JSP编程
  • Java编程
  • 易语言
  • Ruby编程
  • Perl编程
  • AJAX
  • 正则表达式
  • C语言
  • 编程开发

    javascript实现防止被iframe的方法

    2018-04-09 07:41:26 次阅读 稿源:互联网
    零七广告

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

    方法一:

    <script>// 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);</script>

    方法二:

    <script>// 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);</script>

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

    零七网部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与零七网进行文章共享合作。

    零七广告
    零七广告
    零七广告
    零七广告