检测嵌入在 Javascript 中的 iFrame [英] Detect iFrame embedding in Javascript

查看:20
本文介绍了检测嵌入在 Javascript 中的 iFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含特定页面的应用程序——我们称之为页面 A.页面 A 有时是顶级页面,但有时也作为 iframe 嵌入页面 B 中.所有页面都来自同一服务器,并且没有跨域问题.

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 上运行的油脂猴脚本.油脂猴脚本如何检测页面 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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