国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js實現防止被iframe的方法

2019-11-20 12:06:31
字體:
來源:轉載
供稿:網友

本文實例講述了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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凯里市| 云霄县| 平和县| 新安县| 阿克苏市| 宜兰县| 保山市| 依安县| 安溪县| 林甸县| 岳西县| 长阳| 金门县| 桂平市| 华蓥市| 盐源县| 安宁市| 黄陵县| 新营市| 屏东县| 泰兴市| 泾源县| 五指山市| 南雄市| 尚志市| 西城区| 广元市| 历史| 即墨市| 丰都县| 石阡县| 德阳市| 台山市| 韶关市| 汾西县| 汽车| 长沙市| 栾川县| 焦作市| 略阳县| 西吉县|