-1

i want to know how to make it when a a button is pressed it will redirect you to a chosen url. something like this:

<button onclick = "link()">Press to go to link!</button>

function link(){
//leads to url
}
Ben
  • 31
  • 6

2 Answers2

0

You can use window.open to open in new tab.

function link(){
  window.open('http://www.google.com');
}
<button onclick = "link()">Press to go to link!</button>

or

function link(){
  window.location.href = 'http://www.google.com'; //Will take you to Google.
}
<button onclick = "link()">Press to go to link!</button>
DecPK
  • 24,537
  • 6
  • 26
  • 42
0

You can try something like this:

<button class="btn" onclick="window.location.href = 'https://www.stackoverflow.com';">Click this link</button>

or

<a href="https://www.stackoverflow.com"><button>Click this link</button></a>

This will direct the page to a expected link

Deskman
  • 26
  • 2