Difference between _Blank/_self and Blank/self

Asked

Viewed 4,144 times

10

I wonder if there is any recommendation in the use of Html attributes target with or without the _ before the value, I see that it’s kind of standard to use it with _, but if it is absent the redirect also works:

<a href="https://www.google.com" target="_blank">Blank com _</a>
<a href="https://www.google.com" target="blank">Blank sem _</a>
<a href="https://www.google.com" target="_self">Self com _</a>
<a href="https://www.google.com" target="self">Self sem _</a>

2 answers

10


The undescore (_) prefixed in _blank or _self has the function of indicating where the link will be opened. The first in a new tab, the second in the tab itself.

The _blank indicates that the link will open at all times in a new tab, no matter how many times it is clicked: if you click 100 times, 100 new tabs will open.

If you omit the _, using only blank, target loses the specific function and becomes only a common target, meaning that you are opening a new tab with the name "Blank". Then, whenever you click on the link, the browser will check if it already has a tab open with that name. If it has, it loads the link in the already opened tab, if it does not, it opens a new one. The same goes for target="self", or target="qualquercoisa" etc..

  • Thanks Sam, very interesting this, I really did not imagine that these functionalities existed.

5

About underscore (underline) see that according to this W3C documentation it should precede special key words reserved. Without it the string is like a string normal and is interpreted differently by the browser https://www.w3.org/TR/2009/WD-html5-20090423/browsers.html#browsing-context-Names

A Valid browsing context name is any string with at least one Character that does not start with a U+005F LOW LINE Character. (Names Starting with an underscore are reserved for special Keywords.)

PORTUGUÊS "A valid navigation context name is any string with at least one character that does not start with a U + 005F LOW LINE character. (Names starting with an underscore are reserved for special keywords.)"

U+005F Unicode Character 'LOW LINE' _

However in the W3C HTML validator itself the code passed smoothly

inserir a descrição da imagem aqui

Take the test https://validator.w3.org/#validate_by_input

Another curiosity is that this attribute is case-insensitive https://www.w3.org/TR/2011/WD-html-markup-20110525/datatypes.html#common.data.browsing-context-name-or-keyword-def

  • 1

    Nice Hugo, thank you very much!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.