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 method and specify the target as "_blank". Here is an example:

<button onclick="openNewTab()">Open Google in a new tab</button>

function openNewTab() {"", "_blank");

In this example, when the button is clicked, the openNewTab() function is called which uses the method to open the URL in a new tab. The second parameter "_blank" tells the browser to open the URL in a new tab, instead of the current tab.

Latest Questions

javascript How to Check if a Javascript Array Includes a Given Value? javascript How to Completely Uninstall Nodejs, and Reinstall From Scratch on Mac OS X? javascript How to Map Values of a Javascript Object to a New Object Using a Function?