Today I saw an article on CSS-Tricks about the target attribute of the HTML element, and how the target attribute value is not a keyword. I haven’t looked at the target attribute in detail before, so I’ll review it here.

An HTML element (or anchor element) can specify where to display linked resources through its target attribute.

Attribute values

Normally the A element loads the link on the current page without the target attribute. We add the target=”_blank” keyword to the element when we need to load a link every time in a new TAB, which is often used.

   <a target="_blank" href="https://juejin.cn/">More code, more digging</a>
Copy the code

Target can also be set to any value without the keyword. Setting the target=”blank” property will also open the first clicked link in a new TAB, but the next time you open the link will load the link in that TAB instead of opening a new TAB. The blank is simply a name.

   <a target="blank" href="https://juejin.cn/">More code, more digging</a>
Copy the code

When you need to load links but don’t need to open a new TAB, redirect target to Blank.

   <a target="blank" href="https://juejin.cn/">More code, more digging</a>
Copy the code

Differences between keywords and other names

  1. Target =”_blank” is a special keyword that opens a link in a new TAB each time.
  2. Target =”blank” will open the first clicked link in a new TAB, but any subsequent shared links will open target=”blank” in the same newly opened TAB.

conclusion

Very interesting content. The above is the content of this share, if there is any mistake, please correct.