码迷,mamicode.com
首页 > Web开发 > 详细

js判断是否在iframe中

时间:2016-12-19 11:10:29      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:top   判断   window   nbsp   sel   name   ram   方法   parent   

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中.

js判断是否在iframe中

标签:top   判断   window   nbsp   sel   name   ram   方法   parent   

原文地址:http://www.cnblogs.com/zycbloger/p/6196493.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!