Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close child window, redirect parent window

Tags:

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?

like image 333
bear Avatar asked Apr 13 '11 22:04

bear


People also ask

How do I close the child window from the parent window?

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!

How do I pass a value from child window to parent window?

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.

Why is window opener null?

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.

How do I know if my child's window is closed?

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.


2 Answers

from child:

opener.location.href = '/redirect'; close(); 
like image 104
Nobody Avatar answered Oct 05 '22 13:10

Nobody


The key is to use window.opener to access the parent window:

<script>     window.opener.location = '/redirect.html';     window.close(); </script> 
like image 38
Marc Abramowitz Avatar answered Oct 05 '22 13:10

Marc Abramowitz