bear
bear

Reputation: 11625

Close child window, redirect parent window

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?

Upvotes: 24

Views: 90501

Answers (4)

Gaurav123
Gaurav123

Reputation: 5219

Please try below :

window.opener.location.reload();
close();
  1. window.opener.location.reload(); will reload the parent window.
  2. close() will close the child window

It works fine for me.

Upvotes: 2

Marc Abramowitz
Marc Abramowitz

Reputation: 3597

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

<script>
    window.opener.location = '/redirect.html';
    window.close();
</script>

Upvotes: 20

user578895
user578895

Reputation:

from child:

opener.location.href = '/redirect';
close();

Upvotes: 30

Naftali
Naftali

Reputation: 146350

try this:

var parent = window.opener;

parent.location ='some url';

window.close();

here is an example in a fiddle: http://jsfiddle.net/maniator/jGbZq/

Upvotes: 2

Related Questions