Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button to open link in new tab

I am making a website and I want a new tab to open at a specific address when I click a button.

This is the html for my button:

<button id="AsDownload" onclick="AsDownload();">Download</button>

And this is my javascript:

function AsDownload(){
    chrome.tabs.create({url:"https://alexanderhawking.itch.io/asteroid-racer"});
};

But it is not working and I can't figure out why, can someone help me?

like image 491
Alex Hawking Avatar asked Dec 23 '22 04:12

Alex Hawking


1 Answers

In addition to the other answers, add "_blank" to open in a new tab if you intend on using a JavaScript function.

function AsDownload() {
  //window.open(pathString, target);
  window.open("https://alexanderhawking.itch.io/asteroid-racer", "_blank");
};
<button id="AsDownload" onclick="AsDownload()">Download</button>
like image 184
O.O Avatar answered Dec 31 '22 14:12

O.O