我正在写一个基于iframe的Facebook应用程序.现在我想使用相同的html页面来呈现普通网站以及facebook中的画布页面.我想知道我是否可以确定页面是在iframe中加载还是直接在浏览器中加载?
如果父级本身也在iframe中,我如何从iframe中的页面判断?
说明:
我的主页home.html包含iframe
<iframe src="sample.html"></iframe>
Run Code Online (Sandbox Code Playgroud)
我需要检测if home.html(即:parent sample.html)是否在iframe中.
代码sample.html:
if(self==window)
{
alert('home.html is not in iframe');
}
else
{
alert('home.html is in iframe');
}
Run Code Online (Sandbox Code Playgroud)
我的问题不是重复的.这是一个不同的案例.