Net-informations.com

Open a URL in a new tab (and not a new window)

Whether to open the URL in a new tab or a new window, is actually controlled by the user's browser preferences. There is no way to override it in JavaScript. The window.open() method is used to open a new browser window or a new tab depending on the browser setting and the parameter values.

Open URL in New Tab using JavaScript

How to Open a URL in a new tab

If you want to open URl in a new tab, you have to use "_blank" in second parameter of window.open(). Also, do not add a third parameter to it as it will result in the opening of a new window rather than a tab.

run this source code Try it Yourself

Click the button to open a new tab

Full Source | JavaScript

You could do it this way calling a direct function, or by adding an event listener to your DOM object.

Method-2 : Open URL in New Tab

run this source code Try it Yourself

Click the button to open a new tab

Full Source | JavaScript

You cannot expect the same behavior for window.open to be true across all of Internet Explorer, Opera, Firefox, and Chrome, because of the different ways in which they handle a user's browser preferences.










net-informations.com (C) 2022    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About