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");
From there, you just call the reload method (e.g.: window. parent. location. reload() ).
self. close(); should do it. That should work from within the popup.
window. close(); or this: top. window. close(); you should be able to close it.
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>
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With