In JS how to open link in new tab ?

If you want to open a link in a new tab using JavaScript, you can use the method. Here's an example:

const link = "";
const win =, "_blank");

The method opens a new browser window or tab, depending on the user's browser settings.

  • The first argument is the URL of the page to open,
  • and the second argument is the name of the window or tab. The "_blank" value specifies that the link should be opened in a new tab or window.

Finally, the win.focus() method sets the focus to the newly opened window or tab.

Here is an online example on JSFiddle:

Note that in HTML (without JavaScript), you can open a link in a new tab by setting the target attribute of an <a> tag to "_blank". Here is an example:

<a href="" target="_blank">Open in new tab</a>