国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 盐源县| 库尔勒市| 神木县| 驻马店市| 固阳县| 永川市| 西乌| 洪洞县| 大姚县| 云阳县| 浦江县| 晋州市| 沭阳县| 新安县| 巩义市| 东阿县| 板桥市| 新蔡县| 舒城县| 莎车县| 鄂托克旗| 若尔盖县| 南投县| 赤峰市| 新田县| 阳原县| 西盟| 鹤壁市| 莒南县| 克东县| 遂宁市| 平凉市| 上杭县| 宜良县| 祁门县| 周至县| 新巴尔虎右旗| 高雄县| 松江区| 新绛县| 灵宝市|