How to make link open in new tab

There are a few ways to make a link open in a new tab:

Method 1: Using the target attribute

You can add the target attribute to the link tag and set its value to _blank. This will open the link in a new tab.

Example:

<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank">Link to open in new tab</a>

Method 2: Using the rel attribute

You can add the rel attribute to the link tag and set its value to noopener noreferrer. This will open the link in a new tab and prevent the parent page from being affected by the new page.

Example:

<a rel="nofollow" target="_blank" href="https://www.example.com" rel="noopener noreferrer">Link to open in new tab</a>

Method 3: Using JavaScript

You can use JavaScript to open the link in a new tab. You can add an event listener to the link and use the window.open method to open the link in a new tab.

Example:

<a rel="nofollow" target="_blank" href="https://www.example.com" onclick="window.open(this.href, '_blank'); return false;">Link to open in new tab</a>

Method 4: Using a library or framework

If you're using a library or framework like jQuery, you can use its methods to open the link in a new tab. For example, you can use the window.open method provided by jQuery.

Example:

<a rel="nofollow" target="_blank" href="https://www.example.com" onclick="$('a').attr('target', '_blank'); return false;">Link to open in new tab</a>

Note that the target attribute is not supported in HTML5, so you may need to use one of the other methods if you're using HTML5.