Href in new tab
You want to open a link in a new tab when a user clicks on it. You can achieve this by adding the target
attribute to the a
tag and setting its value to _blank
.
Here's an example:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank">Open in new tab</a>
This will open the link in a new tab when the user clicks on it.
Alternatively, you can use the rel
attribute and set its value to noopener
to prevent the new tab from being able to access the parent page's context.
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank" rel="noopener">Open in new tab</a>
This is a good practice to prevent potential security vulnerabilities.
You can also use JavaScript to achieve this. For example:
<a onclick="window.open('https://www.example.com', '_blank')">Open in new tab</a>
This will also open the link in a new tab when the user clicks on it.
Note that the target
attribute is not supported in HTML5, so you may need to use the rel
attribute or JavaScript to achieve this in modern browsers.