最新国产好看的视频,伊人天堂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)文章

最新評論

勐海县| 蓬溪县| 疏附县| 乌恰县| 育儿| 本溪市| 大邑县| 广东省| 濮阳市| 桦南县| 大同县| 通州市| 江川县| 通州区| 宜宾市| 杭锦旗| 平舆县| 女性| 乾安县| 芜湖市| 廊坊市| 温州市| 满洲里市| 通山县| 德清县| 闸北区| 新乐市| 色达县| 黄浦区| 乡城县| 乌海市| 卫辉市| 通渭县| 洪雅县| 屯留县| 瑞安市| 潞西市| 瑞丽市| 策勒县| 禄丰县| 南溪县|