Refresh parent window when the pop-up window is closed

后端 未结 4 1885
梦如初夏
梦如初夏 2020-12-14 12:31

Is there any way I can refresh the parent window when a popup window is closed without adding any javascript code to the popup window?

I have a page parent.php on wh

4条回答
  •  余生分开走
    2020-12-14 12:51

    To make this work in all major browsers, 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();
        }
    };
    

    So the answer to your question is generally no, if you need your code to work in all browsers, in particular IE.

提交回复
热议问题