一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

js top.location判断自身是否是顶级窗口

时间:2013-01-08 编辑:简简单单 来源:一聚教程网

顶级窗口的地址:top.location

本窗口的地址:self.location

 代码如下 复制代码

if(top.location!=self.location){
top.location = self.location;
}

具体实现程序

 代码如下 复制代码

if (window.top !== window.self) { // are you trying to put self in an iframe?
  try {
    if (window.top.location.host) { // this is illegal to access unless you share a non-spoofable document domain
      // fun times
    } else {
      bust(); // chrome executes this
    }
  } catch (ex) {
    bust(); // everyone executes this
  }
}

热门栏目