问题描述
我有一个具有特定页面的应用程序 - 让我们称之为页面A.页面A有时是顶级页面,但有时也会嵌入到页面B中的iframe中。所有页面都来自同一台服务器并且没有跨域问题。
I have an application that has a certain page -- let's call it Page A. Page A is sometimes a top-level page, but also sometimes is embedded as an iframe within page B. All pages come from the same server and there are no cross-domain issues.
我有一个在页面A上运行的greasemonkey脚本.illipmonkey脚本如何检测页面A是否在iframe上下文中?
I have a greasemonkey script that runs on page A. How can the greasemonkey script detect whether page A is within the iframe context or not?
推荐答案
如果页面A本身有框架(我知道这可能不是这种情况)具体实例)。更可靠和有意义的测试将是:
Looking at frame length breaks down generally if page A itself has frames (I know this might not be the case for this specific instance). The more reliable and meaningful test would be:
if (window!=window.top) { /* I'm in a frame! */ }
这篇关于在Javascript中检测iFrame嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!