This is a trick,

function openInNewTab(url) {
  window.open(url, '_blank').focus();
}

// Or just
window.open(url, '_blank').focus();

In most cases, this should happen directly in the onclick handler for the link to prevent pop-up blockers, and the default "new window" behavior. You could do it this way, or by adding an event listener to your DOM object.

<div onclick="openInNewTab('www.test.com');">Something To Click On</div>

Reference: Open a URL in a new tab using JavaScript

Answer from Duke on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › Window › open
Window: open() method - Web APIs | MDN - Mozilla
By default, window.open opens the page in a new tab. If popup is set to true, it requests that a minimal popup window be used. The UI features included in the popup window will be automatically decided by the browser, generally including an address bar only.
Discussions

JavaScript to open new Tab Window - Support - Themeco Forum
Hi Team, I am using the following JS and CSS as column links on my home page. But I want two of the links of open new windows because they are external links. How can I alter the code to do that… jQuery( document ).rea… More on theme.co
🌐 theme.co
4
0
January 7, 2022
Opening tab - javascript - window.open - background
Hi all I am opening a window.open(URL) which works fine, however my javascript (I am using a chrome addon to run the code) shifts focus to the new opened tab. I would like the focus to remain on the current tab whilst opening the new tab in the background. How can I achieve this>? ALTERNATIVELY, ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
April 10, 2021
javascript - Open a new window on click and new tab on right click of a home page layout link - Salesforce Stack Exchange
But I am finding difficult in opening a new tab because when i right click I didnot find the open new window activce in popup. Any help or Ideas are appriciated. ... Javascript provides a way to detect if right or left button on the mouse is clicked. You can listen to the click event and then ... More on salesforce.stackexchange.com
🌐 salesforce.stackexchange.com
April 20, 2015
How to open a new tab *on the background* in Javascript?
If you go to about:config and filter on "inbackground" there are several preferences that control this for various causes of tabs opening. More on reddit.com
🌐 r/firefox
1
1
January 27, 2021
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-open-url-in-new-tab-using-javascript
How to Open URL in New Tab using JavaScript? - GeeksforGeeks
Second Parameter ("_blank"): Tells the browser to open the URL in a new tab. Return Value: The method returns a reference to the new tab/window or null if it fails.
Published   August 21, 2025
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-open-url-in-a-new-window-using-javascript
How to open URL in a new window using JavaScript? - GeeksforGeeks
August 21, 2025 - The window.open() method is used to open a new browser window or a new tab, depending on the browser settings and the parameter values provided. Here’s how you can use it: ... Note: All the parameters are optional.
🌐
Attacomsian
attacomsian.com › blog › javascript-open-url-in-new-tab
Open a URL in a new tab or window on button click in JavaScript
October 12, 2022 - In the event handler, use the window.open() method to open the link in a new tab.
Find elsewhere
🌐
Squash
squash.io › how-to-open-a-url-in-a-new-tab-using-javascript
How to Open a URL in a New Tab Using JavaScript - Squash.io
April 30, 2024 - To open a URL in a new tab using JavaScript, you can use the window.open() method. This method opens a new browser window or tab, depending on the user's browser settings.
🌐
JavaScript.info
javascript.info › tutorial › frames and windows
Popups and window methods
The syntax to open a popup is: window.open(url, name, params): ... An URL to load into the new window.
🌐
W3Schools
w3schools.com › jsref › met_win_open.asp
Window open() Method
window.open("http://www.google.com/"); window.open("https://www.w3schools.com/"); Try it Yourself » · Open a new window.
🌐
Themeco
theme.co › support
JavaScript to open new Tab Window - Support - Themeco Forum
January 7, 2022 - Hi Team, I am using the following JS and CSS as column links on my home page. But I want two of the links of open new windows because they are external links. How can I alter the code to do that… jQuery( document ).ready(function($) { $(’#column-boats’).on(‘click touched’, function() { window.location.href = ‘https://www.easttexasboatrentals.com/home.html’; }); $(’#column-vans’).on(‘click touched’, function() { window.location.href = ‘/reservations/’; }); $(’#junglefloat’).on(‘click touch...
🌐
CodexWorld
codexworld.com › home › how to guides › how to open url in new tab using javascript
How to Open URL in New Tab using JavaScript - CodexWorld
April 15, 2023 - The JavaScript window.open() method opens a new browser window. Use _blank in the second parameter of window.open() method to open a URL in a new tab using JavaScript.
🌐
DEV Community
dev.to › digvijaysingh › how-to-open-a-new-tab-or-window-using-javascript-5ebc
How to Open a New Tab or Window using Javascript? - DEV Community
October 23, 2020 - var win = window.open('https://google.com/', '_blank'); if (win) { //Browser allows the new tab to open win.focus(); } else { //Browser has blocked it alert('Please allow popups for this website'); } Source : How to open New tab using javascript or jquery and open href in it?
🌐
UsefulAngle
usefulangle.com › post › 232 › javascript-open-url-new-window-tab
How to Open URL in a New Tab with Javascript - UsefulAngle
A URL can be opened in a new tab in Javascript using the window.open() method, and giving _blank as its second parameter.
🌐
Zipy
zipy.ai › blog › how-to-open-a-url-in-a-new-tab-and-not-a-new-window
how to open a url in a new tab (and not a new window)
April 12, 2024 - JavaScript stands at the core of dynamic web development, offering a plethora of methods to manipulate the DOM and control the browser's behavior. One such capability is opening URLs in new tabs using the window.open() method.
🌐
Reintech
reintech.io › blog › tutorial-working-with-the-window-open-method
Working with the window.open() Method | Reintech media
January 13, 2026 - The window.open() method is a powerful function in JavaScript used to open new browser windows or tabs and manipulate existing ones. It accepts three parameters: URL, window name, and window features.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Opening tab - javascript - window.open - background - JavaScript - The freeCodeCamp Forum
April 10, 2021 - Hi all I am opening a window.open(URL) which works fine, however my javascript (I am using a chrome addon to run the code) shifts focus to the new opened tab. I would like the focus to remain on the current tab whilst o…
🌐
Temp Mail
tempmail.us.com › temp mail › blog › javascript › javascript: using new tabs to open urls rather than popup windows
JavaScript: Using New Tabs to Open URLs Rather Than Popup
July 24, 2024 - Basic ways for opening URLs in new tabs, such as target="_blank" and window.open(url, '_blank'), cover most circumstances. However, more advanced strategies should also be considered.
🌐
Stack Exchange
salesforce.stackexchange.com › questions › 72810 › open-a-new-window-on-click-and-new-tab-on-right-click-of-a-home-page-layout-link
javascript - Open a new window on click and new tab on right click of a home page layout link - Salesforce Stack Exchange
April 20, 2015 - Open a new window on click and new tab on right click of a home page layout link. I managed to open a new window with following syntax. window.open(url, mywindowName, height="200", width="400"); ...
🌐
GoLinuxCloud
golinuxcloud.com › home › javascript › how to open a new tab in javascript? [solved]
How to open a new tab in JavaScript? [SOLVED] | GoLinuxCloud
March 13, 2023 - The window.open() method is a built-in JavaScript method that allows the opening of a new browser window or tab. This method takes two parameters, the URL of the page to be opened and the target attribute that specifies where to open the link.