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

JavascriptFront End TechnologyObject Oriented Programming

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.

raja
Published on 06-Jun-2021 12:32:21
Advertisements