检查网页是否位于Google Chrome的Iframe中 [英] Check if page is in Iframe for Google Chrome

查看:547
本文介绍了检查网页是否位于Google Chrome的Iframe中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了很多窗口属性来查看iframe中的页面是否可以判断它是否在iframe中。我曾尝试过:

I have tried many properties of window to see if a page in an iframe can tell if it is in an iframe. I have tried:

if(top.location!= self.location) //doesn't work in Google Chrome
   alert("I am in an iframe!")

这不起作用在所有浏览器上,但Chrome)。我正在为Firefox和Chrome编写一个userscript,但Chrome确实不行。有没有办法判断Chrome是否可以检测到它的页面是否在iframe中?

And this doesn't work (works on all browsers but Chrome). I am writing a userscript for Firefox and Chrome but Chrome really doesn't behave. Is there a way to tell if Chrome can detect if its page is in an iframe?

推荐答案

这适用于框架我认为它也适用于iFrames

This works for frames I would assume it also works with iFrames

if (top === self) { 
  // no frame
} else { 
  //frame 
}

这篇关于检查网页是否位于Google Chrome的Iframe中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆