views:

52

answers:

5

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?

+2  A: 

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

Pekka
good answer, but why `target="_blank"` ?
nickf
@nickf to prevent the page from opening in the current window if JS is disabled. That part is optional, but in many cases you won't want it replacing the current document
Pekka
A: 

window.opener property?

Check this out - http://www.webreference.com/js/tutorial1/opener.html

Floyd Pink
A: 

If you opened a window with window.open(), you may use the opener reference to access the window that is the opener.

jAndy
+1  A: 

Use window.opener.location.href in javascript

For example,

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

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.

Eli Grey