window.open的子级不会在父窗口中调用函数

问题描述

| parent.html
<html>
    <head>
        <script type=\"text/javascript\">
            function openWin()
            {
                myWindow=window.open(\'child.html\',\'\',\'width=200,height=100\');
            }
            function callback(){
                alert(\"test\");
            }
        </script>
    </head>
    <body>
        <input type=\"button\" value=\"Open \'myWindow\'\" onclick=\"openWin()\" />
    </body>
</html>
child.html
<html>
    <head>
       <script type=\"text/javascript\">
          window.opener.callback();
       </script>
    </head>
    <body>
    </body>
</html>
问题是子页面在FF,IE中而不是在Chrome中调用页面的回调函数。 任何想法 ?     

解决方法

发生问题是由于Chrome安全性错误。域,协议和端口必须匹配。但是,从本地文件系统打开页面时也会发生这种情况。 从服务器打开页面,应该没有任何问题。     ,问题可能是chrome如何运行javascript的方式。 Chrome浏览器有时会如此快且较早地运行js,甚至DOM还没有准备好进行操作。在您的child.html中尝试一下
<script type=\"text/javascript\">
setTimeout(function(){window.opener.callback();},100);
</script>
我不确定这是否对您确切,我在chrome上使用jQuery.ready()遇到了此问题。