您的位置:首页 > 运维架构

关于window.opener无效问题

2015-11-23 16:11 946 查看
问题描述:

在父窗口中window.open()打开一个子窗口,  子窗口通过window.opener.document.getElementById().innerHTML="" 来给父窗口传至时无效

经过测试, 在IE10中可行, 但是在opera和chrome中无效

a.html

<body>
<span id="fatherWin"></span><br/>
<a href="javascript:void(0)" onclick="window.open('b.html','_blank')">getChildWindow</a>
</body>
b.html
<pre name="code" class="html"><body>
<scritp>
window.opener.document.getElementById('fatherWin').innerHTML="I'm the Father Window";
</script>
</body>


将b.html进行修改以后,opera和chrome中测试, 发现alert(1)执行, alert(2)不执行, 说明是window行异常

<pre name="code" class="html"><body>
<scritp>
alert(1);
window.opener.document.getElementById('fatherWin').innerHTML="I'm the Father Window";
alert(2);
</script>
</body>



之后与之进行了长时间的斗争, 最终发现一些端倪

不要用webkit核心浏览器来测试本地资源!!!

上述代码部署到服务器中就可测试通过

详情可以参照该文章:http://www.coding123.net/article/20141105/chrome-file-access-can-not-get-iframe-parent-opener-nul.aspx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息