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

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

问题描述

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

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

说明:

Explanation:

我的主页 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,则为true:

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 (窗口层次结构的最顶层窗口)和另一个窗口对象( self parent )。

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天全站免登陆