javascript 如何在 iframe 之外打开新链接?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4201388/
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 do I open new links outside of an iframe?
提问by Sean
Is there any way to make an iframe act as if it were part of the page. Such as when I click a link, it either will open the links in a new tab/window by default, or have it so that when a link is clicked, it will open in the same window, but not just the iframe?
有什么办法可以让 iframe 表现得好像它是页面的一部分。例如,当我单击一个链接时,它要么默认在新选项卡/窗口中打开链接,要么让它在单击链接时在同一窗口中打开,而不仅仅是 iframe?
回答by Nick Craver
You can just set the targetattribute. To open in the current top window (top frame):
您可以只设置target属性。要在当前顶部窗口(顶部框架)中打开:
<a href="http://example.com" target="_top">Link Text</a>
Or to open in a new window:
或在新窗口中打开:
<a href="http://example.com" target="_blank">Link Text</a>
There's also _parentfor the parent window (not necessarily the top) and _selffor the current window (the default).
还有_parent父窗口(不一定是顶部)和_self当前窗口(默认)。
回答by mrtsherman
Do you have control of the content that is in the iframe?
您是否可以控制 中的内容iframe?
You could use target=_topfor the links.
您可以target=_top用于链接。

![javascript (![]+[])[+[]]... 解释为什么会这样](/res/img/loading.gif)