Computer >> Computer tutorials >  >> Programming >> Javascript

How to open a URL in a new tab (and not a new window) using JavaScript?


Opening of a URL in a new tab depends on the browser and the user's browser preferences. There is nothing you can do in code to force open a link strictly in a new tab.

However if you want the user to open it in either new tab or window(depending on their preferences) you can add the following attribute to the anchor() tag −

target="_blank"

This will instruct the browser to leave the current page as is and open the link in a new tab/window.