Make link open in new tab
To make a link open in a new tab, you can add the target
attribute to the link tag and set 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 clicked.
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 cookies and other information:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank" rel="noopener">Open in new tab</a>
Note that the noopener
attribute is not supported in older browsers, so you may want to use the target
attribute alone if you need to support older browsers.
You can also use JavaScript to achieve this. For example:
<a rel="nofollow" target="_blank" href="https://www.example.com" onclick="window.open(this.href, '_blank'); return false;">Open in new tab</a>
This will open the link in a new tab when clicked, and prevent the default link behavior from occurring.