Setting parent window URL from a child window?
This is what I am trying to do: O开发者_如何学运维nce 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?
Use window.opener.location.href in javascript
For example,
<a href="javascript:void(0);" onclick="window.opener.location.href='linkedFile.html';">Click me!</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
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.
精彩评论