[英]Changing url of one iframe from another
我有一个包含2个iframe代码的页面:
<iframe src="top.html" seamless="seamless" width=100% height=100% id="up" name="up" frameborder="0"></iframe>
<iframe src="main.html" seamless="seamless" width=100% height=800px id="main" frameborder="0"></iframe>
在main.html中,我有以下代码:
parent.frames['up'].location.href = "top.html";
想法是刷新“ up” iframe。 有时它可以正常工作,有时什么也没发生,有时我会遇到一个例外:
未捕获到的SecurityError:阻止了源为“ null”的帧访问源为“ null”的帧。 协议,域和端口必须匹配。
我究竟做错了什么?
试试下面的代码:
parent.frames["up"].location.replace("top.html")
我发现了问题。 通过双击加载页面时会发生问题。 iframe及其父级的域必须相同。 通过双击加载文件时,它们都具有域“ null”,并且由于(null === null)返回false,因此引发了异常。 为了使此代码起作用,我必须从Web服务器运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.