-1

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.

TBNRVivo
  • 1
  • 3

2 Answers2

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
  • Sorry, I don't use href. – TBNRVivo Sep 18 '21 at 16:05