How do I redirect a user to a page if they click a button? This is for a login page. I have tried href
but it doesn't work. I don't know .php so I am using js.
Asked
Active
Viewed 236 times
-1

TBNRVivo
- 1
- 3
-
3Does this answer your question? [How do I redirect to another webpage?](https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage) – nima Sep 16 '21 at 08:29
-
If this is for a login page, why you don't just submit your form? – mchev Sep 16 '21 at 08:41
-
1Thanks, This is pretty useful! – TBNRVivo Sep 18 '21 at 16:06
2 Answers
0
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">redirect</button>
<script>
function myFunction() {
window.location.href = "http://stackoverflow.com";
}
</script>
</body>
</html>

nfn
- 621
- 2
- 8
- 22
0
Create an HTML button that acts like a link
<a href='https://ide.geeksforgeeks.org/'>
<button>
Click Here
</button>
</a>
-
it isn't valid HTML5 according to the HTML5 Spec Document from W3C. https://stackoverflow.com/questions/6393827/can-i-nest-a-button-element-inside-an-a-using-html5 – mchev Sep 16 '21 at 08:39
-