Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open popup and refresh parent page on close popup

I opened a popup window by window.open in JavaScript, I want to refresh parent page when I close this popup window.(onclose event?) how can I do that?

window.open("foo.html","windowName", "width=200,height=200,scrollbars=no"); 
like image 637
ArMaN Avatar asked May 29 '12 02:05

ArMaN


People also ask

How to refresh parent window in JavaScript?

From there, you just call the reload method (e.g.: window. parent. location. reload() ).

How do I close a popup in JavaScript?

self. close(); should do it. That should work from within the popup.

How do I turn off iframe parent window?

window. close(); or this: top. window. close(); you should be able to close it.


2 Answers

You can access parent window using 'window.opener', so, write something like the following in the child window:

<script>     window.onunload = refreshParent;     function refreshParent() {         window.opener.location.reload();     } </script> 
like image 103
Morrison Cole Avatar answered Oct 04 '22 01:10

Morrison Cole


The pop-up window does not have any close event that you can listen to.

On the other hand, there is a closed property that is set to true when the window gets closed.

You can set a timer to check that closed property and do it like this:

var win = window.open('foo.html', 'windowName',"width=200,height=200,scrollbars=no");    var timer = setInterval(function() {        if(win.closed) {           clearInterval(timer);           alert('closed');       }   }, 1000);  

See this working Fiddle example!

like image 30
Zuul Avatar answered Oct 04 '22 01:10

Zuul