I've got a page which opens a child window, from a parent.
After the user has done something in the child window, I need the child window to close, and its parent window to be redirected to a page, on the click of a button in the child window.
Any ideas?
A child window opens as separate window as a tab. Go back to the parent and click “Close child” and the child window closes. Viola!
From a child window or a small window once opened, we can transfer any user entered value to main or parent window by using JavaScript. You can see the demo of this here. Here the parent window is known as opener. So the value we enter in a child window we can pass to main by using opener.
You open a window from another domain/subdomain. In this case you don't have access to parent window that opened the target window because security permissions don't allow that. For example if you open a page of site2.com from a page of site1.com the target window has it's opener null.
If you store a reference to the child window when you call window. open() , then you can poll using setInterval() to see whether the window is still open using the window. closed property.
from child:
opener.location.href = '/redirect'; close();
The key is to use window.opener
to access the parent window:
<script> window.opener.location = '/redirect.html'; window.close(); </script>
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