Kaddy
Kaddy

Reputation: 1266

Setting parent window URL from a child window?

This is what I am trying to do: Once submit a form on my main JSP/HTML page a new page with some link opens. When I click on any of the link the link should open in the parent Window. I.e the Window I started from. How do i do this?

Upvotes: 4

Views: 28522

Answers (4)

austinabraham_a
austinabraham_a

Reputation: 57

window.opener.location.href = "https://www.google.com/";

This will reload the parent window once the URL(String) is assigned to the location.href.

Upvotes: 0

Pekka
Pekka

Reputation: 449515

You'll need JavaScript for this. HTML's target can't target the window's parent (opener) window.

The following will open the page in the parent window if JavaScript is enabled, and open it in a new window if it is disabled. Also, it will react gracefully if the current page does not have an opener window.

<a href="page.php" 
   onclick="if (typeof window.opener != 'undefined')   // remove this line break
            window.opener.location.href = this.href; return false;"  
   target="_blank">
Click
</a>

MDC Docs on window.opener

Upvotes: 4

Eli Grey
Eli Grey

Reputation: 35895

Use parent.location.href if it's on the same page in an iframe. Use opener.location.href if it's another entire tab/window.

Upvotes: 3

Kranu
Kranu

Reputation: 2567

Use window.opener.location.href in javascript

For example,

<a href="javascript:void(0);" onclick="window.opener.location.href='linkedFile.html';">Click me!</a>

Upvotes: 11

Related Questions