Js open url in new tab

A simple one!

To open a URL in a new tab using JavaScript, you can use the window.open() method or the location.href property.

Method 1: Using window.open()

window.open('https://www.example.com', '_blank');

This will open the URL https://www.example.com in a new tab.

Method 2: Using location.href

location.href = 'https://www.example.com';

This will open the URL https://www.example.com in the current tab. To open it in a new tab, you can use the target attribute:

location.href = 'https://www.example.com';
location.href = 'https://www.example.com';

Method 3: Using an anchor tag

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

This will create an anchor tag that opens the URL https://www.example.com in a new tab when clicked.

Note that in all cases, the _blank value is used to specify that the URL should be opened in a new tab.