防止网页被嵌入框架的代码

try{

  top.location.hostname; //Chrome不报错

  if (top.location.hostname != window.location.hostname) {

    top.location.href =window.location.href; //其他浏览器有异常

  }}

catch(e){

  top.location.href = window.location.href;

}

ref:http://www.ruanyifeng.com/blog/2010/08/anti-frameset_javascript_codes_continued.html

 

if (self!=top){ window.top.location.replace(self.location); //打开自己网站的页面 }

ref:https://blog.csdn.net/shaerdong/article/details/53208511

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章