Button for opening an HTML button in a new tab

So, this is a simple code for a button to open a specific link

<button class="btn btn-success" onclick="location.href='http://google.com';"> Google</button> 

but it opens on the same page, I want the link to open in a new tab.

+5
source share
4 answers

You can use the following.

 window.open( 'https:http://google.com', '_blank' // <- This is what makes it open in a new window. ); 

in HTML

  <button class="btn btn-success" onclick=" window.open('http://google.com','_blank')"> Google</button> 

plunkr

+14
source

With Bootstrap, you can use the anchor as a button.

 <a class="btn btn-success" href="https://www.google.com" target="_blank">Google</a> 

And use target="_blank" to open the link in a new tab.

+1
source

try it

 window.open(urlValue, "_system", "location=yes"); 
0
source

Use '_blank'. It will not only open the link in a new tab, but the state of the original web page will also remain unaffected.

0
source

Source: https://habr.com/ru/post/1237377/


All Articles