Option 1
Rather than using a
<button>
, use an
<a>
tag with
target="_blank"
. You can use CSS to style the link to look like a button if required.
<a href="Link1" target="_blank">Link1</a>
<a href="Link2" target="_blank">Link2</a>
Option 2:
Use a different function name for each button, as suggested by RMC in the comments.
<button onclick="openLink1();">Link1<button>
<button onclick="openLink2();">Link2<button>
function openLink1(){
window.open("Link1");
}
function openLink2(){
window.open("Link2");
}
Option 3:
Use a single function for all buttons, and an argument to the function to specify which URL to open.
<button onclick="myFunction('Link1');">Link1<button>
<button onclick="myFunction('Link2');">Link2<button>
function myFunction(url){
window.open(url);
}