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>
Pekka
2010-08-24 05:20:15
good answer, but why `target="_blank"` ?
nickf
2010-08-24 05:22:08
@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
2010-08-24 05:24:13
A:
window.opener
property?
Check this out - http://www.webreference.com/js/tutorial1/opener.html
Floyd Pink
2010-08-24 05:20:46
A:
If you opened a window with window.open()
, you may use the opener
reference to access the window that is the opener.
jAndy
2010-08-24 05:21:17
+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
2010-08-24 05:22:33
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
2010-08-24 05:31:57