1

I am trying to reload a parent window if child window get closed.

Here is my current code which opens a popup window, but it has not programmed for refresh parent window when it get closed. I dont know what code to add

jQuery(document).ready(function($) {

    jQuery('.top-buttons a').live('click', function(e){
        e.preventDefault();
        newwindow=window.open($(this).attr('href'),'','height=500,width=850');

        if (window.focus) {newwindow.focus()}
        return false;
    });
});
user007
  • 3,203
  • 13
  • 46
  • 77

6 Answers6

2

Try:

newwindow = window.open($(this).attr('href'), '', 'height=500,width=850');
newwindow.onbeforeunload = function () {
    console.log("popup closed")
}
darshanags
  • 2,519
  • 1
  • 13
  • 19
1

You can access the parent window from the child window using window.opener : example

So to reload the parent window just call window.opener.location.reload() documentation when you handle the close event.

basarat
  • 261,912
  • 58
  • 460
  • 511
1

Try the below code on close event of the child window

      window.opener.location.reload();
Samy
  • 632
  • 4
  • 14
1

You can use window.opener to access parent window and window.reload() to reload it when child window is closed.

Please refer below URLS:

how to access parent window object using jquery?

javascript: How Can a parent window know that its child window closed?

Community
  • 1
  • 1
web2008
  • 914
  • 4
  • 11
0

in the parent window define an unload event like

 function doStuffOnUnload() {
     alert("Unloaded!");
  }

 if (typeof win.attachEvent != "undefined") {
     newwindow.attachEvent("onunload", doStuffOnUnload);
 } 
 else if (typeof win.addEventListener != "undefined") {
    newwindow.addEventListener("unload", doStuffOnUnload, false);
  }

from here i took it from

Community
  • 1
  • 1
Dakait
  • 2,531
  • 1
  • 25
  • 43
0

you need window.opener

window.opener.location.href = window.opener.location.href;

should be added to the closing event of the window.

hammus
  • 2,602
  • 2
  • 19
  • 37