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

首頁 > 語言 > JavaScript > 正文

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

2024-05-06 16:22:35
字體:
供稿:網(wǎng)友

這篇文章主要介紹了js實(shí)現(xiàn)防止被iframe的方法,實(shí)例分析了兩種比較常用的javascript防止頁面被iframe的技巧,非常簡單實(shí)用,需要的朋友可以參考下

本文實(shí)例講述了js實(shí)現(xiàn)防止被iframe的方法。分享給大家供大家參考。具體如下:

方法一:

 

 
  1. <script> 
  2. // Break out of an iframe, if someone shoves your site 
  3. // into one of those silly top-bar URL shortener things. 
  4. // 
  5. // Passing `this` and re-aliasing as `window` ensures 
  6. // that the window object hasn't been overwritten. 
  7. // 
  8. // Example: 
  9. // var window = 'haha, punked!'; 
  10. // 
  11. // Note: Probably unnecessary, but just for kicks. 
  12. (function(window) { 
  13. if (window.location !== window.top.location) { 
  14. window.top.location = window.location; 
  15. })(this); 
  16. </script> 

方法二:

 

 
  1. <script> 
  2. // A more cryptic one-liner, to awe & impress. 
  3. // 
  4. // No need to protect `window` since `this` is 
  5. // immutable, and at the topmost level means 
  6. // `window` anyways. Here, we compare locations 
  7. // on the left side of the "&&" and execute the 
  8. // code in parenthesis if that condition is 
  9. // true (top location isn't iframe location). 
  10. // 
  11. // Otherwise, nothing happens. It's basically an 
  12. // if statement without wrapping curly brackets. 
  13. // 
  14. // Weird, I know. But pretty cool, right? :) 
  15. this.top.location !== this.location && (this.top.location = this.location); 
  16. </script> 

希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 永昌县| 如皋市| 宁夏| 桦南县| 金乡县| 山东| 乌兰浩特市| 巴林左旗| 长岭县| 麻城市| 登封市| 名山县| 昭觉县| 报价| 上林县| 两当县| 湖南省| 广丰县| 绿春县| 嘉荫县| 济宁市| 永兴县| 连城县| 佛坪县| 美姑县| 临安市| 万盛区| 新巴尔虎右旗| 营口市| 章丘市| 鞍山市| 涟水县| 昌江| 黔西县| 营山县| 新巴尔虎右旗| 博湖县| 吕梁市| 大兴区| 勃利县| 蓬安县|