Search code examples
javascriptwindow.opener

Javascript call parent function from child after window.opener.location.reload


I have two pages. The parent page opens a popup with javascript. From the child page(popup), i reload the parent page. After that I would like to invoke a method called doSomething().

Parent page:

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

Child page:

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

But javascript invokes the doSomething() first and only after that performes window.opener.location.reload().

Is there a way to know on child page when window.opener.location.reload(true) has completed before calling the second method?


Solution

  • What about your are using it like this:

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

    Because your are using the whole document you could check if its already loaded or not.