javascript, iframe - 从 iframe 导航/关闭父窗口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5952927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
javascript, iframe - navigate/close parent window from iframe
提问by zozo
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).
一个带有文本/任何内容的页面,其中还包括一个 iframe(iframe 中的页面是由我创建的,因此我可以访问它,我可以修改其内容)。
What I need to do is that when I access a link from the iframe to open it on the mother page (navigate).
我需要做的是,当我从 iframe 访问链接以在母页(导航)上打开它时。
Until now I kind of failed to do that so any help would be appreciated.
直到现在我都没有这样做,所以任何帮助将不胜感激。
For any further info just ask.
如需更多信息,请询问。
回答by Naftali aka Neal
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:
或者使用 javascript:
<a href="javascript:window.parent.location = 'somthing.html';" >GO SOMEWHERE!</a>
回答by Brad Wilkie
If all you need to do is change the parent window's location from inside the iframe, it is very simple:
如果您需要做的只是从 iframe 内部更改父窗口的位置,则非常简单:
window.parent.location = 'newWindow.html';
Or if you are using a link, just use it's "target" attribute.
或者,如果您正在使用链接,只需使用它的“目标”属性。