Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh parent window when the pop-up window is closed

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 which users can click "open popup" to open a popup window. This popup window shows some flash content and its not possible for me to add something like

window.onunload = function(){ 
  window.opener.location.reload(); 
}; 

to the popup window page markup.

Is there any other method to achieve this? Thanks

like image 310
Kay Avatar asked Nov 24 '10 14:11

Kay


People also ask

What is window opener location reload?

opener. location. reload(); Open the parent of a current window and reload the location.

How do I close parent window?

Double clicking on the file opens it in the browser and closes it immediately. We can also open a new window by adding another line of code. This opens a new window and closes the parent window. All the above functions can be called in the onload event of the body tag in the page.

How do you refresh a page in JavaScript?

You can use the location. reload() JavaScript method to reload the current URL. This method functions similarly to the browser's Refresh button. The reload() method is the main method responsible for page reloading.

What is window opener?

opener. The Window interface's opener property returns a reference to the window that opened the window, either with open() , or by navigating a link with a target attribute. In other words, if window A opens window B , B. opener returns A .


1 Answers

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.

like image 155
Tim Down Avatar answered Sep 23 '22 08:09

Tim Down