关于window.opener无效问题

问题描述:

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

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

a.html

<body>
    <span id="fatherWin"></span><br/>
    <a href="javascript:void(0)" οnclick="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核心浏览器来测试本地资源!!!

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


版权声明:本文为lee272616原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。