防止网页嵌入

  try{
      top.location.hostname; //表明不存在跨域(或者未使用框架),就不采取操作
      if (top.location.hostname != window.location.hostname) { //兼容Chrome浏览器
        top.location.href =window.location.href;
      }
    }catch(e){
      top.location.href = window.location.href; //表明存在跨域,就对top对象进行URL重导向
    }

 当前框架和顶层框架的域名不相同时禁止嵌入

 

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

posted on 2012-07-02 15:48  け凨浩  阅读(120)  评论(0编辑  收藏  举报

导航