Html 锚标签目标属性中_self、_top、_parent的区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18470097/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 12:41:30  来源:igfitidea点击:

Difference between _self, _top, and _parent in the anchor tag target attribute

htmlhyperlinkanchor

提问by Joseph Rex

I know _blankopens a new tab when used with the anchor tag and also, there are self-defined targets I use when using framesets but I will like to know the difference between _parent, _selfand _top.

我知道_blank与锚标记一起使用时会打开一个新选项卡,并且在使用框架集时我使用了自定义目标,但我想知道_parent,_self_top.

回答by Brian Ellis

While these answers are good, IMHO I don't think they fully address the question.

虽然这些答案很好,但恕我直言,我认为它们并没有完全解决这个问题。

The target attribute in an anchor tag tells the browser the target of the destination of the anchor. They were initially created in order to manipulate and direct anchors to the frame system of document. This was well before CSS came to the aid of HTML developers.

锚标记中的目标属性告诉浏览器锚的目的地的目标。它们最初的创建是为了操纵和引导锚点到文档的框架系统。这早在 CSS 帮助 HTML 开发人员之前。

While target="_self"is default by browser and the most common target is target="_blank"which opens the anchor in a new window(which has been redirected to tabs by browser settings usually). The "_parent", "_top"and framenametags are left a mystery to those that aren't familiar with the days of iframe site building as the trend.

虽然target="_self"是浏览器的默认设置,最常见的目标是target="_blank"在新窗口中打开锚点(通常已通过浏览器设置重定向到选项卡)。的"_parent""_top"并且framename标签留下一个谜那些不熟悉的iframe网站建设作为潮流的日子。

target="_self"This opens an anchor in the same frame. What is confusing is that because we generally don't write in frames anymore (and the frameand framesettags are obsolete in HTML5) people assume this a same window function. Instead if this anchor was nested in frames it would open in a sandbox mode of sorts, meaning only in that frame.

target="_self"这将在同一帧中打开一个锚点。令人困惑的是,因为我们通常不再用框架编写(并且frameframeset标签在 HTML5 中已经过时),人们认为这是一个相同的窗口函数。相反,如果此锚点嵌套在框架中,它将以某种沙盒模式打开,这意味着仅在该框架中。

target="_parent"Will open the in the next level up of a frame if they were nested to inside one another

target="_parent"如果它们相互嵌套,将在框架的下一级打开

target="_top"This breaks outside of all the frames it is nested in and opens the link as top document in the browser window.

target="_top"这会在它嵌套的所有框架之外中断,并在浏览器窗口中将链接作为顶部文档打开。

target="framenameThis was originally deprecated but brought back in HTML5. This will target the exact frame in question. While the namewas the proper method that method has been replaced with using the ididentifying tag.

target="framename这最初被弃用,但在 HTML5 中被带回。这将针对有问题的确切框架。虽然这name是正确的方法,但该方法已被替换为使用id识别标签。

<!--Example:-->

<html>
<head>
</head>
<body>
<iframe src="url1" name="A"><p> This my first iframe</p></iframe>
<iframe src="url2" name="B"><p> This my second iframe</p></iframe>
<iframe src="url3" name="C"><p> This my third iframe</p></iframe>

<a href="url4" target="B"></a>
</body>
</html>

回答by Jukka K. Korpela

Section 6.16 Frame target namesin the HTML 4.01 spec defines the meanings, but it is partly outdated. It refers to “windows”, whereas HTML5 drafts more realistically speak about “browsing contexts”, since modern browsers often use tabs instead of windows in this context.

HTML 4.01 规范中的第6.16框架目标名称定义了含义,但部分已经过时。它指的是“窗口”,而 HTML5 草案更实际地谈到“浏览上下文”,因为现代浏览器在这种上下文中经常使用选项卡而不是窗口。

Briefly, _selfis the default (current browsing context, i.e. current window or tab), so it is useful only to override a <base target=...>setting. The value _parentrefers to the frameset that is the parent of the current frame, whereas _top“breaks out of all frames” and opens the linked document in the entire browser window.

简而言之,_self是默认值(当前浏览上下文,即当前窗口或选项卡),因此仅覆盖<base target=...>设置才有用。该值_parent指的是当前框架的父框架集,而_top“脱离所有框架”并在整个浏览器窗口中打开链接的文档。

回答by Srinivas

target="_blank"

target="_blank"

Opens a new window and show the related data.

打开一个新窗口并显示相关数据。

target="_self"

target="_self"

Opens the window in the same frame, it means existing window itself.

在同一个框架中打开窗口,这意味着现有的窗口本身。

target="_top"

target="_top"

Opens the linked document in the full body of the window.

在整个窗口中打开链接的文档。

target="_parent"

target="_parent"

Opens data in the size of parent window.

以父窗口的大小打开数据。

回答by Syed Maqsood

Here is a practical example of Anchor tag with different

这是一个不同的锚标签的实际例子

Target Attribute

目标属性