Javascript在window.opener.location.reload之后调用来自子节点的父函数

时间:2015-08-12 13:39:11

标签: javascript window.opener

我有两页。父页面打开一个带有javascript的弹出窗口。 从子页面(弹出窗口),我重新加载父页面。之后我想调用一个名为doSomething()的方法。

父页面:

<html>
    <head>
        <script type='text/javascript'>
             function doSomething(){
                 // code ...
             }
        </script>
    </head>
    <body>
        // open child page
    </body>
</html>

子页面:

<html>
    <head>
    </head>
    <body>
        <script type='text/javascript'>
            window.opener.location.reload(true);
            window.opener.doSomething();
        </script>
    </body>
</html>

但javascript首先调用doSomething(),然后才调用window.opener.location.reload()

在调用第二种方法之前,window.opener.location.reload(true)完成后,有没有办法知道子页?

1 个答案:

答案 0 :(得分:1)

你的使用方式如下:

window.opener.location.reload(true);
if(document.readyState === "complete") {
    window.opener.doSomething();
}

因为您正在使用整个文档,所以可以检查它是否已经加载。

相关问题