How can I open a new tab using javascript without switching to the new tab?
For example, when a user clicks on a link a new tab is to be opened, but the user should stay on the current tab.
The JavaScript window. open() method allows you to open URL in the browser tab or window. You can use _self value in the second parameter of the window. open() method to open URL in the same tab and in the same window with JavaScript.
Method 1: Ctrl+Click Simply press and hold the Ctrl key (Cmd on a Mac) and then click the link in your browser. The link will open in a new tab in the background.
The web browser automatically focuses on the new tab, but you can call the focus back:
function openWindow( url ) { window.open(url, '_blank'); window.focus(); } <a href="http://www.example.com/" onclick="javascript:openWindow(this.href);return false;">Click Me</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With