Html 超链接目标中的 _top 有什么作用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16230959/
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
What does _top in the hyperlink target do?
提问by user2219520
I sometimes see target="_top"
in an anchor tag. What does it do?
我有时会target="_top"
在锚标签中看到。它有什么作用?
<a href="http://foobar.com" target="_top">Foobar</a>
回答by hamon
If the link is in an iframe
, the new webpage will not be loaded in the iframe
but instead the browser will open the page in the window itself
如果链接在iframe
,则不会在 中加载新网页,iframe
而是浏览器将在窗口本身中打开页面
回答by Ch?a bi?t
target=:
目标=:
_top
: Opens the linked document in the full body of the window
_top
:在整个窗口中打开链接的文档
_blank
: Opens the linked document in a new window or tab
_blank
:在新窗口或选项卡中打开链接的文档
_self
: Opens the linked document in the same frame as it was clicked (this is default)
_self
:在单击时在同一框架中打开链接的文档(这是默认设置)
_parent
: Opens the linked document in the parent frame
_parent
: 在父框架中打开链接的文档
framename
: Opens the linked document in a named frame
framename
: 在命名框架中打开链接文档
回答by Tim Medora
It's a browsing contextname.
这是一个浏览上下文名称。
A valid browsing context name or keyword is any string that is either a valid browsing context name or that is an ASCII case-insensitive match for one of: _blank, _self, _parent, or _top.
有效的浏览上下文名称或关键字是任何字符串,它要么是有效的浏览上下文名称,要么是以下各项之一的不区分大小写的 ASCII 匹配:_blank、_self、_parent 或 _top。
Take a look at the matrix here, which describes the behavior of the target
attribute in different scenarios.
看看这里的矩阵,它描述了target
属性在不同场景下的行为。
The practical effect is that _top
references the topmost window (technically the top level browsing context).
实际效果是_top
引用最顶层的窗口(技术上是顶层浏览上下文)。
<a href="http://foo.com" target="_top">a link</a>
tells the browser to navigate to "foo.com" not in its own frame, but in the topmost frame. If the current frame isthe topmost frame, the URL will open in the same window.
<a href="http://foo.com" target="_top">a link</a>
告诉浏览器导航到“foo.com”不是在它自己的框架中,而是在最顶层的框架中。如果当前框架是最顶层的框架,则 URL 将在同一窗口中打开。
See also: Browsing Contexts(if you're in the mood for some deep reading).
另请参阅:浏览上下文(如果您想深入阅读)。
回答by Tim Medora
target="_top"
will open the link at the top level of all defined framesets.
target="_top"
将在所有定义的框架集的顶层打开链接。
回答by l2aelba
as @hamon said
正如@hamon所说
Example to use _top with jQuery
在 jQuery 中使用 _top 的示例
If your site is contained in a frameset
如果您的站点包含在框架集中
$(document).ready(function() {
if(top.location != location) {
$('a, form').each(function() {
if(!this.target) {
this.target = '_top';
}
});
}
});
So.. All links in your site gonna open in new windownot in the frame(Credit)
所以..您网站中的所有链接都将在新窗口中打开而不是在框架中(来源)
回答by Apb
target="_top"
attribute causes the "target" of the hyperlink to display at the top level of all currently defined framesets. It opens the linked document in the full body of the window
target="_top"
属性使超链接的“目标”显示在所有当前定义的框架集的顶层。它会在整个窗口中打开链接的文档