最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js實現(xiàn)防止被iframe的方法

 更新時間:2015年07月03日 15:35:25   作者:不吃皮蛋  
這篇文章主要介紹了js實現(xiàn)防止被iframe的方法,實例分析了兩種比較常用的javascript防止頁面被iframe的技巧,非常簡單實用,需要的朋友可以參考下

本文實例講述了js實現(xiàn)防止被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程序設(shè)計有所幫助。

相關(guān)文章

最新評論

巍山| 沅江市| 宜黄县| 大埔县| 望都县| 隆昌县| 通海县| 邻水| 安顺市| 丽江市| 雷州市| 临沭县| 抚远县| 丹江口市| 张家口市| 丰原市| 比如县| 安阳县| 奈曼旗| 山阴县| 常熟市| 丹凤县| 霞浦县| 萨嘎县| 庐江县| 禄劝| 黄平县| 扬中市| 芒康县| 大庆市| 石棉县| 庐江县| 原平市| 新郑市| 子洲县| 威海市| 泽库县| 东光县| 吉首市| 广南县| 高尔夫|