the pop-up window does not close after reloading the parent window

advertisements

In my parent jsp page I've used:

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

And in child (popup window) I've used:

<script type="text/javascript">
        window.onunload = function() {
                if (window.opener && !window.opener.closed) {
                window.opener.popUpClosed();
                }
        };
</script>

by this code, parent window is reloading after inserting data from popup window but popup window is not closing, I've to manually close the popup window. How can the popup window be made self close??


To close the window in your popup change the code like this:

<script type="text/javascript">
        window.onunload = function() {
                if (window.opener && !window.opener.closed) {
                window.opener.popUpClosed();
                }
                window.close();
        };
</script>

Refer here: How to close the current window. onunload is called whenever your page unloads. If you are posting data, by a submit button, you are unloading the document.

This is not the same as closing the windows. If you want to capture only the close of the window, you should use something like:

window.onbeforeunload = windowExit;
function windowExit(){
    //do somethng
    //check that you are not submitting.
}