检查父窗口是否为 iframe [英] Check if parent window is iframe or not

查看:31
本文介绍了检查父窗口是否为 iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 iframe 中的页面判断父级本身是否也在 iframe 中?

How can I tell from a page within an iframe, if the parent itself is also within an iframe?

解释:

我的主页 home.html 包含一个 iframe

My home page home.html contains an iframe

<iframe src="sample.html"></iframe>

我需要检测 home.html(即:sample.html 的父级)是否在 iframe 内.

I need to detect if home.html (ie: parent of sample.html) is within an iframe.

sample.html 中的代码:

if(self==window)
{
    alert('home.html is not in iframe');
}
else
{
    alert('home.html is in iframe');
}

我的问题不是重复的.情况不同.

My question is not a duplicate. It's a different case.

推荐答案

如果窗口不是框架/iframe,则为真:

This is true if a window is not a frame/iframe:

if(self==top)

如果您想查看给定窗口的父窗口是否为框架,请使用:

If you like to see if the parent window of the given window is a frame, use:

if(parent==top)

这是top(窗口层次结构的最顶层窗口)和另一个窗口对象(selfparent)的简单比较.

It's a simple comparision of top (the most top window of the window hierarchy) and another window object (self or parent).

这篇关于检查父窗口是否为 iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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