How to Open a URL in a New Tab Using Javascript?

javascript

To open a URL in a new tab using Javascript, you can use the window.open() method and specify the target as "_blank". Here is an example:

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

<script>
function openNewTab() {
  window.open("http://www.google.com", "_blank");
}
</script>

In this example, when the button is clicked, the openNewTab() function is called which uses the window.open() 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?