Search code examples
javascriptpopupparent-childwindow.opener

Parent window of a popup not reloading


I have opened a popup window and trying to refresh the parent window before closing parent window.

Below is my code. I tried using window.top, top.location, etc but nothing working for me!

Any help?

$("#closeit").click(function(){
    opener.location.focus();
    opener.location.reload();
    window.close();
});

Solution

  • you need to handle the unload event handler in the pop-up and do the reloading in the main window. In the main window, add

    function popUpClosed() {
        window.location.reload();
    }
    

    In the pop-up:

    window.onunload = function() {
        if (window.opener && !window.opener.closed) {
            window.opener.popUpClosed();
        }
    };