Html 如何在同一个 iframe 中打开 iframe 链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17802765/
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
How to open a iframe link within the same iframe?
提问by Kalim
I have to load outside server URL within iframe which has some links, when user clicks on a link it opens outside the iframe. But I want to open it within the same iframe.
我必须在 iframe 中加载外部服务器 URL,其中有一些链接,当用户单击它在 iframe 外部打开的链接时。但我想在同一个 iframe 中打开它。
How is it possible?
这怎么可能?
采纳答案by Subir Kumar Sao
You should specify target name of the iframe.
您应该指定 iframe 的目标名称。
<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
<p><a href="http://www.w3schools.com" target="iframe_a">www.google.com</a></p>
回答by Quentin
Links in documents loaded in iframes will, by default, open in the same frame.
默认情况下,iframe 中加载的文档中的链接将在同一框架中打开。
If the document overrides that default behaviour (e.g. with target="_top"
) then the document will load elsewhere.
如果文档覆盖该默认行为(例如使用target="_top"
),则文档将加载到其他地方。
There is no way for the document containing the frame to change that behaviour (of the document loaded into the frame) if it is from an "outside server" since security restrictions prevent interaction with the DOM of documents form other origins.
如果包含框架的文档来自“外部服务器”,则包含框架的文档无法更改该行为(加载到框架中的文档),因为安全限制阻止与来自其他来源的文档的 DOM 进行交互。
回答by Kara
You will need to set the target=_self
attribute in the link like this:
您需要target=_self
像这样在链接中设置属性:
<a href="http://google.com/" target="_self">Google</a>
but if you are loading an external website you have no control over this may not be possible.
但如果您正在加载外部网站,则您无法控制这可能是不可能的。
回答by stefancarlton
checkout the _target attribute on a hyperlink: http://www.w3schools.com/tags/att_a_target.aspyou want "_self" e.g.
在超链接上签出 _target 属性:http: //www.w3schools.com/tags/att_a_target.asp你想要“_self”,例如
<a href="#" target="_self">link</a>
回答by user1721135
You can not influence an iframe with a source on a different domain.
您不能影响具有不同域上的源的 iframe。
If it was on the same domain you could remove the target blank with javascript, but since its in a different domain you have no influence over the html.
如果它在同一个域中,您可以使用 javascript 删除目标空白,但由于它位于不同的域中,因此您对 html 没有影响。
Hope that helps and saves you countless hours trying the impossible.
希望能帮助并为您节省无数时间来尝试不可能的事情。