简体   繁体   中英

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. Ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM