阻止浏览器在iframe文档中加载自定义框架集 [英] Prevent browser from loading a custom frameset in an iframe's document
问题描述
我一直在尝试与来自同一个域的两个 iframe 进行通信,这两个 iframe 是从另一个域加载到一个页面中的。
I have been trying to communicate two iframes from same domain which are loaded in a page from another domain.
问题是浏览器在iframe的内容上创建自定义框架集。
我无法使用 parent.iframes [x] .name 从iframe中检索iframe名称,因为脚本将 frameset 作为父级。
The problem is browser creates a custom frameset over the content of iframe. I cant retrieve the iframe names from within the iframe using parent.iframes[x].name because the script addresses frameset as the parent.
以下是我的实际HTML代码 -
Below is my actual html code -
<html>
<head>
</head>
<body>
<p>iframe1</p>
<script type="text/javascript">
var frames = parent.frames;
for(var i=0; i < frames.length; i++)
{
if(frames[i].name != "undefined")
alert(frames[i].name);
}
</script>
</body>
</html>
以下是浏览器生成的内容 -
Below is what browser generated -
<!--inside iframe-->
<html>
<head></head>
<frameset border="0" rows="100%,*" cols="100%" frameborder="no">
<!--actual document goes inside frame tag-->
<frame name="TopFrame" scrolling="yes" noresize="" src="http://abnormalz.stuffshake.com/fframe.html">
<frame name="BottomFrame" scrolling="no" noresize="">
<noframes></noframes>
</frameset>
</html>
这个问题有解决办法吗?
Is there any solution to this problem ?
您可以在 http://stuffshake.com/parent.html 上查看测试
推荐答案
只需使用localStorage或sessionStorage即可。由于两个iframe都来自同一个域,因此它们共享相同的localStorage。如果修改了值,LocalStorage将发送事件。
Just use localStorage or sessionStorage. Since both iframes are from the same domain, they share the same localStorage. LocalStorage sends events if a value was modified.
自IE8起支持。
这篇关于阻止浏览器在iframe文档中加载自定义框架集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!