Live data from Hacker News

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

kyrylo.org

61–70 of 203 posts

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

#61
This to me was always obvious. They wanted a way to define special targets that had specific behaviour but didn't want people to get confused when they tried to call something "blank" and then it created a new window. Having a special character at the start of your name by default is extremely uncommon so you're very safe if you add a special character at the start of the name for special purposes it won't conflict with someone's actual desires. "_blank" isn't the only one. "_parent", "_top", etc also exist.

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

#65

Because making "blank" a reserved word would've been so much harder than making "_blank" one... /s

In HTML 4.01 and XHTML "_blank" was an illegal ID, so a frame could not use it. Therefore, there was no chance of breaking existing code. "blank" however, could be in use when they introduced this feature and break existing pages.

This all changed in HTML5 when IDs could start with special characters like "_".

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

#66
post #62
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.

And a lot of SO answers.

I was more thinking of javadoc, or other languages where people can automatically generate documentation from the code comments they wrote and 97 out of 100 comments is the function name written as a sentence ("reserveItem(): reserves an item")

For anyone who writes these, please just leave it blank and revisit it later

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

#67

Yeah it's a magic value. No shit? Was anyone really confused by this?

To be fair, a lot of people they might assume that the target attribute can ONLY take a few discrete magic values if they haven't worked with multiple frames on one document, so it's an obvious question to ask why it HAS to start with an underscore. (_blank has the same uniqueness as blank, if you assume the ONLY options are _blank and _self, the only commonly used values in modern web development.)

Though... yeah it's pretty unsatisfying of an answer generally.

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

#68
post #60
post #36

Earlier quoted context omitted.

But why was _name the naming syntax for reserved keywords, specifically?

Probably inspired by C and C++ which reserve names starting with an underscore for the implementation (more precisely, they reserve names starting with `_[_A-Z]` everywhere, and all other names starting with `_` in the global scope only).

I nice factoid: in Erlang, `_` if functional. It means "I don't care about this variable". When pattern matching you can put `_` to not bind value in function or pattern to anything or prepend a variable with `_` to tell compiler that you won't be using it, but it's there for "documentation" purposes. For example `[A|_]=List` will extract first element of list into A and ignore rest of list. Underscore has some other uses too.

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

#69
post #36

Earlier quoted context omitted.

Yeah it’s not a great explanation. To me (and I’m of the era they’re describing so I used it a lot) it’s simply that _blank is a reserved keyword that means open the link in a new, unnamed window. Other reserved keywords for “target” are _self (default value), _parent, and _top. https://www.w3schools.com/TAgs/att_a_target.asp

But why was _name the naming syntax for reserved keywords, specifically?

>But why was _name the naming syntax for reserved keywords, specifically?

As with so many things in software engineering, the answer comes down to "some programmer in the 70s working on a UNIX system had to make an arbitrary decision about something, and no one ever had a good reason to change it again."

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

#70
post #66
post #62

Earlier quoted context omitted.

And a lot of SO answers.

I was more thinking of javadoc, or other languages where people can automatically generate documentation from the code comments they wrote and 97 out of 100 comments is the function name written as a sentence ("reserveItem(): reserves an item") For anyone who writes these, please just leave it blank and revisit it later

I second your motion.
Post reply on HN