js 判断是否在iframe中

1.方式一

if (self.frameElement && self.frameElement.tagName == "IFRAME") {
  alert('在iframe中');
}

2.方式二
if (window.frames.length != parent.frames.length) {
  alert('在iframe中');
}

3.方式三
if (self != top) {
  alert('在iframe中');
}

以上用任何一种都可以判断代码是否在iframe中.

猜你喜欢

转载自blog.csdn.net/zhuoganliwanjin/article/details/81448997
今日推荐