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
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.
🌐
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.
🌐
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
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.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-open-url-in-new-tab-using-javascript
How to Open URL in New Tab using JavaScript? - GeeksforGeeks
The return value of window.open() is a reference to the newly created window or tab.
Published   August 21, 2025
🌐
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.
Find elsewhere
🌐
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.
🌐
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.
🌐
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.
🌐
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...
🌐
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
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.
🌐
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
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"); ...
🌐
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.
🌐
Educative
educative.io › answers › how-to-open-a-link-in-a-new-tab-with-html-and-javascript
How to open a link in a new tab with HTML and JavaScript
No, HTML’s target="_blank" or JavaScript’s window.open() method are the primary methods for opening links in a new tab.