判断是否在iframe中,页面跳出iframe访问。

1、方式一

if(self.frameElement && self.frameElement.tagName == 'IFRAME'){

  top.window.location.replace(url);//如果是在iframe中直接让父元素跳出iframe。

}

2、方式二

if(window.frames.length != parent.frames.length){

  top.window.location.replace(url);

}

3、方式三

if(self != top){

  top.window.location.replace(url);

}

原文地址:https://www.cnblogs.com/zj911005/p/8916241.html