开发者

Child of window.open doesn't call function in parent window

parent.html

<html>
    <head>
        <script type="text/javascript">
            function openWin()
            {
                myWindow=window.open('child.html','','width=200,height=100');
            }
开发者_Go百科            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>

And the problem is that the child page calls parent's page callback function in FF, IE but not in Chrome.

Any idea ?


Problem happens because of Chrome security error. Domains, protocols and ports must match. But it also happens when page is open from local files system.

Open your page from server, it should be without any problems.


The problem might be the way how chrome run javascript. Chrome sometimes run the js so fast and early and even the DOM is not ready for manipulation. Try this in your child.html

<script type="text/javascript">
setTimeout(function(){window.opener.callback();}, 100);
</script>

I am not sure if this is the exact problem for you, I encountered this problem with jQuery.ready() on chrome.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜