'How to redirect to a URL when a button is clicked [duplicate]
I am trying to redirect to a link when the button is clicked, but it is not working, please need a working code, please.
function myFunction() {
document.getElementById("mycom").location.href = "http://mywebsite.com/home.html"";
}
<button type="button" onclick="myFunction()">Try it</button>
Solution 1:[1]
To redirect change your function to the following:
function myFunction() {
window.location = 'http://mywebsite.com/home.html'
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sean Lawton |
