javascript, iframe - navigate/close parent window from iframe

跟風遠走 提交于 2019-12-12 10:57:31

问题


Good day to all.

I have this setup:

One page with text/whatever, that also includes an iframe (the page in iframe is created by me so I have access to it, I can modify its content).

What I need to do is that when I access a link from the iframe to open it on the mother page (navigate).

Until now I kind of failed to do that so any help would be appreciated.

For any further info just ask.


回答1:


In all of the links that you want to affect the parent window do something like this:

<a href="somthing.html" target="_parent">GO THERE!</a>

Or with javascript:

<a href="javascript:window.parent.location = 'somthing.html';" >GO SOMEWHERE!</a>



回答2:


If all you need to do is change the parent window's location from inside the iframe, it is very simple:

 window.parent.location = 'newWindow.html';

Or if you are using a link, just use it's "target" attribute.




回答3:


You should use the target attribute <a href="" target="...">

For all the possible values of target, you can go here.



来源:https://stackoverflow.com/questions/5952927/javascript-iframe-navigate-close-parent-window-from-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!