Languages
[Edit]
EN

HTML - open link in new tab

6 points
Created by:
Elias999
819

In this article, we would like to show you how in a safe way create a link that is opened after a click in a new tab.

Quick solution:

Note (in 2021): when we use target="_blank" attribute in links, in major modern web browsers, it is automatically used rel="noopener" attribute behaving to prevent vulnerabilities - check notification here.

Warning: for security reasons, it is important to use rel="noopener" attribute, even if some tools warns us about unnecessary attribute.

or:

Hint: rel="noopener" is not needed if we know the link opens the safe page (safe page is the page that will not make unsafe opetaion on out web page using JavaScript).

 

Practical example

Edit

In this example, we use a element with additional properties to open the link in a new tab:

  • target="_blank" - specifies to open the linked page in a new tab,
  • rel="noreferrer noopener" - which is a good practice and helps to prevent tabnabbing and hide information about from what page the user came.

Note: the default value of the target property is _self which opens linked page in the current working tab.

 

References

Edit
  1. Link type "noreferrer" - W3C Working Draft
  2. Link type "noopener" - W3C Working Draft

Alternative titles

  1. HTML - open link in new window
  2. HTML - safe way to open link in new window
  3. HTML - safe way to open link in new tab
  4. HTML - noopener example
  5. HTML - noreferrer example
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join