user10442837
user10442837

Reputation:

Opening a link in a new tab in HTML with script (button)

How do I open a link in a new tab with JavaScript?

This is my current code:

 <button id="homePage" class="float-left submit-button">Home</button>
 <script type="text/javascript">
 document.getElementById("homePage").onclick = function () {
    location.href = "https://www.google.com";
 };
 </script >

Upvotes: 0

Views: 150

Answers (1)

Llazar
Llazar

Reputation: 3312

You can use window.open(url, '_blank'); after the location.href.

Upvotes: 1

Related Questions