TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Why does target="_blank" have an underscore in front? (2024)

278 点作者 OuterVale3 个月前

33 条评论

paulirish3 个月前
I went digging in W3C archives to find relevant discussions. There are 4 reserved target names: _blank, _parent, _self, _top.<p>- 1995 Sept <a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;19990202141025&#x2F;http:&#x2F;&#x2F;home.mcom.com&#x2F;eng&#x2F;mozilla&#x2F;2.0&#x2F;relnotes&#x2F;mac-2.0a2.html" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;19990202141025&#x2F;http:&#x2F;&#x2F;home.mcom....</a> Netscape Navigator 2.0a2 release notes including rollout of TARGET.<p>- 1995 Sept <a href="https:&#x2F;&#x2F;lists.w3.org&#x2F;Archives&#x2F;Public&#x2F;www-html&#x2F;1995Sep&#x2F;0034.html" rel="nofollow">https:&#x2F;&#x2F;lists.w3.org&#x2F;Archives&#x2F;Public&#x2F;www-html&#x2F;1995Sep&#x2F;0034.h...</a> First definition of them; spec text provided by &quot;the Netscape Navigator marketing guy&quot;.<p>- 1997 Jan <a href="https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;2018&#x2F;SPSD-html32-20180315&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;2018&#x2F;SPSD-html32-20180315&#x2F;</a> HTML 3.2 published <i>without</i> frame target names specced.<p>- 1997 Aug <a href="https:&#x2F;&#x2F;lists.w3.org&#x2F;Archives&#x2F;Public&#x2F;www-html&#x2F;1997Aug&#x2F;0010.html" rel="nofollow">https:&#x2F;&#x2F;lists.w3.org&#x2F;Archives&#x2F;Public&#x2F;www-html&#x2F;1997Aug&#x2F;0010.h...</a> Roles of these target names clarified<p>- 1997 Dec <a href="https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;html401&#x2F;types.html#h-6.16" rel="nofollow">https:&#x2F;&#x2F;www.w3.org&#x2F;TR&#x2F;html401&#x2F;types.html#h-6.16</a> HTML 4.0 published with target names.<p>I can&#x27;t find any discussion about the choice of character. My guess is that discussion was internal to Netscape as they shipped _then_ specced link target names.
评论 #43165254 未加载
评论 #43166514 未加载
ldjb3 个月前
I was expecting this post to explain why it&#x27;s an underscore specifically, as opposed to a dollar sign, an asterisk, a caret, a tilde or some other special character.<p>I can only assume it&#x27;s a holdover of languages like C where the standard library has some reserved names that start with an underscore.<p><a href="https:&#x2F;&#x2F;devblogs.microsoft.com&#x2F;oldnewthing&#x2F;20230109-00&#x2F;?p=107685" rel="nofollow">https:&#x2F;&#x2F;devblogs.microsoft.com&#x2F;oldnewthing&#x2F;20230109-00&#x2F;?p=10...</a>
评论 #43160523 未加载
评论 #43160614 未加载
评论 #43163389 未加载
评论 #43158436 未加载
评论 #43161255 未加载
bilekas3 个月前
So basically It’s an “_blank” because it is.. Author’s description is, “because if it wasn’t _blank.. it wouldn’t open a new tab.” Reminds me of some university professors I had.
评论 #43160301 未加载
评论 #43161201 未加载
评论 #43160693 未加载
评论 #43161147 未加载
评论 #43160266 未加载
评论 #43162698 未加载
评论 #43158535 未加载
评论 #43160005 未加载
n_plus_1_acc3 个月前
The answer is a little unsatisfying to me. It says that &quot;blank&quot; ca be a frame name, but doesn&#x27;t say why &quot;_blank&quot; can&#x27;t be.
评论 #43159346 未加载
评论 #43158156 未加载
评论 #43158170 未加载
评论 #43160928 未加载
graypegg3 个月前
Tangential, but I would really like frames to come back for incremental document updates, like LiveView&#x2F;Hotwire&#x2F;HTMX. You can just start working like that today with one of those libraries, but it would be so neat to have a common standard for describing an update to a targeted frame.
评论 #43160466 未加载
评论 #43161608 未加载
评论 #43160366 未加载
评论 #43161108 未加载
评论 #43160686 未加载
评论 #43160580 未加载
评论 #43165316 未加载
rco87863 个月前
Why did we move away from this model of web development? If I remember back that far, it seems like fairly soon after this was when the meta starting telling us that frames were bad, and using &lt;table&gt; was bad, etc.<p>It all honestly seemed a lot easier than what has come after.
评论 #43162604 未加载
评论 #43162371 未加载
评论 #43162695 未加载
评论 #43165999 未加载
评论 #43162125 未加载
评论 #43165351 未加载
p4bl03 个月前
&gt; developers needed a way to explicitly tell the browser to open the link in a new tab, free of frame semantics<p>First, it doesn&#x27;t say why an underscore does that, because you could totally have underscores in frame names. My guess as others here is that the underscore prefix dates back from reserved names in C and C++. IIRC the reserved names also included &quot;_self&quot; (even if it was the default), &quot;_parent&quot; (to go up a level in the frame hierarchy) and &quot;_top&quot; to replace the whole page.<p>Second, at the time it was clearly not &quot;open the link in a <i>new tab</i>&quot; but rather in a &quot;<i>new window</i>&quot;. IE was the most used browser back then, by a large proportion, and it didn&#x27;t supports tabs at all.
评论 #43160552 未加载
评论 #43160915 未加载
评论 #43158557 未加载
aryonoco3 个月前
Minor nitpick: browsers used _blank as a special directive to open the link in a new “window”, not a tab. Browsers didn’t have tabs back then, well other than Opera 4.x which was a paid software which never cracked 3% marketshare.
评论 #43158082 未加载
lifthrasiir3 个月前
Shower thought: `&lt;a href=&quot;...&quot; target=&quot;_mobile&quot;&gt;` should transfer a link in a desktop into my phone. Same goes for `target=&quot;_desktop&quot;` but in the opposite direction.
评论 #43157894 未加载
评论 #43158270 未加载
评论 #43159419 未加载
评论 #43157891 未加载
advincze3 个月前
It&#x27;s crappy design. Instead of using a separate property for different functionality like target-new-window=true or sth. They wanted to be clever. I think this is misinterpreting Simplicuty by thinking that an additional property is complicating things
评论 #43164998 未加载
btown3 个月前
The 1995 Frameset proposal from Netscape that started it all: <a href="https:&#x2F;&#x2F;lists.w3.org&#x2F;Archives&#x2F;Public&#x2F;www-html&#x2F;1995Sep&#x2F;0034.html" rel="nofollow">https:&#x2F;&#x2F;lists.w3.org&#x2F;Archives&#x2F;Public&#x2F;www-html&#x2F;1995Sep&#x2F;0034.h...</a><p>&gt; Hi. I&#x27;m the Netscape Navigator marketing guy. Please forgive the temerity with which we submit this new proposal from Netscape to the W3 and IETF for enhancements to HTML 3.0. It pertains to functionality called Frames.<p>...<p>&gt; The NAME attribute is used to assign a name to a frame so it can be targeted by links in other documents (These are usually from other frames in the same document.) The NAME attribute is optional; by default all windows are unnamed.<p>&gt; Names must begin with an alphanumeric character. However, several reserved names have been defined, which start with an underscore. These are currently: _blank Always load this link into a new, unnamed window. _self Always load this link over yourself. _parent Always load this link over your parent. (becomes self if you have no parent). _top Always load this link at the top level. (becomes self if you are at the top).
Cthulhu_3 个月前
My first &quot;web app&quot; used frames, it was good times. Some time later I used backbone.js, and while it was still good times, it did get a lot more complicated (e.g. having to manually disconnect and reconnect &#x27;child&#x27; elements when the main element re-rendered so that they would retain their event handlers).
评论 #43158303 未加载
that_guy_iain3 个月前
This to me was always obvious. They wanted a way to define special targets that had specific behaviour but didn&#x27;t want people to get confused when they tried to call something &quot;blank&quot; and then it created a new window. Having a special character at the start of your name by default is extremely uncommon so you&#x27;re very safe if you add a special character at the start of the name for special purposes it won&#x27;t conflict with someone&#x27;s actual desires. &quot;_blank&quot; isn&#x27;t the only one. &quot;_parent&quot;, &quot;_top&quot;, etc also exist.
dugmartin3 个月前
I&#x27;m guessing it is because the developer at Netscape that added frame support thought about it for 5 seconds and came up with the name. Maybe if Lou Montulli sees this he would know?
knorker3 个月前
On this topic: Please NEVER use target=_blank. If the user wants a new window or tab, then they can open a new window or tab. There are so many websites where navigating around for a bit makes you end up with 5-6 tabs open, all with broken history, thanks to this mis-feature.<p>_blank is evil and user hostile. Don&#x27;t be evil and user hostile.
评论 #43164133 未加载
评论 #43165552 未加载
dataviz10003 个月前
Perhaps for the same reason &quot;World wide web inventor admits forward slashes &#x27;a mistake&#x27;&quot; [0]I wonder what the cumulative years &#x2F; time wasted writing &#x27;:&#x2F;&#x2F;&#x27; or the amount of energy which could have been saved computing it would be?<p>[0] <a href="https:&#x2F;&#x2F;economictimes.indiatimes.com&#x2F;tech&#x2F;internet&#x2F;world-wide-web-inventor-admits-forward-slashes-a-mistake&#x2F;articleshow&#x2F;5123863.cms?from=mdr" rel="nofollow">https:&#x2F;&#x2F;economictimes.indiatimes.com&#x2F;tech&#x2F;internet&#x2F;world-wid...</a>
kilna3 个月前
Underscore prefix in a label has conferred a meaning of private or reserved in the C programming language since at least Unix Version 6 in 1975, which had underscores to denote system level functions and variables. MUMPS in 1966 reserved a % prefix to indicate system variables and routines, so a convention of using a non-alphanumeric character to distinguish scope has been around about as long as ASCII has been the dominant standard for text.
cubefox3 个月前
Are there still legitimate uses for the target attribute, other than _blank?<p>Framesets are obviously out of date, but the target attribute can also be used to always open some links in the same tab with that target name, i.e. not to open a new one when it already exists. Not sure whether this has much of a modern use case.
nubinetwork3 个月前
I think it&#x27;s funny that Mozilla says not to use frames anymore, they work just fine on modern browsers...
评论 #43158530 未加载
wicket3 个月前
I haven&#x27;t done much with HTML for years so I had no idea that modern browsers use &quot;_blank&quot; to open a page in a new tab instead of a new window. This genuinely surprised me, seems like unexpected behaviour or a regression&#x2F;bug. :)
评论 #43161745 未加载
notpushkin3 个月前
You can use target with iframes: <a href="https:&#x2F;&#x2F;jsfiddle.net&#x2F;7szje2a9&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jsfiddle.net&#x2F;7szje2a9&#x2F;</a>
ZoomStop3 个月前
Site is giving me a 403, here is an Archive mirror: <a href="https:&#x2F;&#x2F;archive.ph&#x2F;aDqv3" rel="nofollow">https:&#x2F;&#x2F;archive.ph&#x2F;aDqv3</a>
pyromaker3 个月前
So if we kept frameset in HTML5, we would not have had to do all these JS shenanigans?!?!?! SPA out of the box? :)
评论 #43167906 未加载
bicsi3 个月前
Wait, so frameset is basically htmx?
评论 #43161642 未加载
评论 #43160354 未加载
评论 #43165327 未加载
icedchai3 个月前
Because back in the mid 90&#x27;s, there was Netscape...
mattl3 个月前
Because “blank” can be a real frame name if you want to make your codebase a little harder on purpose.<p>You still see _blank for links opening in new windows, but _parent, _self, etc not so much anymore.
评论 #43157859 未加载
muglug3 个月前
&gt; P.S. Don’t use &lt;frameset&gt;. It’s deprecated in HTML5<p>Tell that to the enterprise email scanning software my Fortune 500 company uses
评论 #43166401 未加载
d--b3 个月前
FWIW, I never heard of the frameset tag, while I did use frames back then.
评论 #43157938 未加载
评论 #43158683 未加载
评论 #43158005 未加载
评论 #43160091 未加载
评论 #43157892 未加载
taco_emoji3 个月前
Yeah it&#x27;s a magic value. No shit? Was anyone really confused by this?
评论 #43160178 未加载
mannyv3 个月前
name collisions.
jwsteigerwalt3 个月前
Love this. Just when you thought you knew all the reserved words, you learn another one.
oneeyedpigeon3 个月前
Because making &quot;blank&quot; a reserved word would&#x27;ve been so much harder than making &quot;_blank&quot; one... &#x2F;s
评论 #43160141 未加载
评论 #43160361 未加载
stop503 个月前
Because its an remnant from the browser wars.
评论 #43161032 未加载