Live data from Hacker News

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

kyrylo.org

111–120 of 203 posts

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

#111
post #41

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.

It would open in a new tab (or specifically, window) if there was no object named "blank" for it to target. The problem with that is subsequent links with the target "blank" would use this same new window. Links with the target "_blank" would each open in individual windows

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

#112
post #18

I was expecting this post to explain why it's an underscore specifically, as opposed to a dollar sign, an asterisk, a caret, a tilde or some other special character. I can only assume it's a holdover of languages like C where the standard library has some reserved names that start with an underscore. https://devblogs.microsoft.com/oldnewthing/20230109-00/?p=10...

As another borrowed convention, JS developers of yore (and likely some today still) used an _ prefix to denote “private” function/methods. Quotes as it’s just a convention - today JS supports # for actual private members in class syntax.

[deleted]

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

#113
post #41

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.

Not quite. Any name would open a new window unless a frame with that name already exists. This includes the case of the name “blank”. In other words, the first time clicking on a link targeting a name would open a new frame (window) with that name, but the second time would load the content into the existing frame, replacing the previous content. In that scheme, there is no way to open an additional new frame each time. The reserved name “_blank” was then defined to have that semantics.

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

#114
post #6
post #3

Because “blank” can be a real frame name if you want to make your codebase a little harder on purpose. You still see _blank for links opening in new windows, but _parent, _self, etc not so much anymore.

The title of the post isn't asking HN users a question

OK.

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

#115
post #113
post #41

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.

Not quite. Any name would open a new window unless a frame with that name already exists. This includes the case of the name “blank”. In other words, the first time clicking on a link targeting a name would open a new frame (window) with that name, but the second time would load the content into the existing frame, replacing the previous content. In that scheme, there is no way to open an additional new frame each ti…

So again as I understand, it's simply because a standard was decided ?

> The (reserved) name “_blank” was then defined to have that semantic.

I guess I was hoping for some interesting quirk with older browsers or something.

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

#116
post #18

I was expecting this post to explain why it's an underscore specifically, as opposed to a dollar sign, an asterisk, a caret, a tilde or some other special character. I can only assume it's a holdover of languages like C where the standard library has some reserved names that start with an underscore. https://devblogs.microsoft.com/oldnewthing/20230109-00/?p=10...

[deleted]

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

#117
post #113

Earlier quoted context omitted.

Not quite. Any name would open a new window unless a frame with that name already exists. This includes the case of the name “blank”. In other words, the first time clicking on a link targeting a name would open a new frame (window) with that name, but the second time would load the content into the existing frame, replacing the previous content. In that scheme, there is no way to open an additional new frame each ti…

So again as I understand, it's simply because a standard was decided ? > The (reserved) name “_blank” was then defined to have that semantic. I guess I was hoping for some interesting quirk with older browsers or something.

It was to avoid the situation of someone naming a frame “blank” without being aware of it having special semantics, or (I’m not completely clear on the history) avoiding breaking compatibility with existing use. That’s much more unlikely with a name like “_blank”. It’s common practice to separate out names with special semantics from general-use names in a syntactic way like that. There’s also “_self”, “_parent”, and “_top”. It’s an extensible scheme where HTML can add further names with special semantics in that reserved name space.

I now agree that the article doesn’t make a particularly good job in explaining all of this.

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

#119
post #86
post #81

Earlier quoted context omitted.

This is exactly what I understood from the article. Your explanation didn't add anything extra.

I actually used the 1.0 version of Netscape Navigator, and did some web development on it back in the day. Originally, _blank, _new, etc. weren’t special. A target ref to a name which wasn’t used would open a new window. If it was already used, it would take you to that open window. People started using _whatever because just ‘blank’ would almost always cause a collision. Eventually it got standardized that it would…

If what you say is accurate then it should have been in the article. Because, as is, GP is correct that it doesn't answer the question!
Post reply on HN