How TO – Redirect to Another Webpage
// Simulate a mouse click: window.location.href = "http://www.w3schools.com"; // Simulate an HTTP redirect: window.location.replace("http://www.w3schools.com");
Simulate a mouse click
<!DOCTYPE html> <html> <head> <script> window.location.href = "https://google.com"; </script> </head> <body> </body> </html>
Simulate an HTTP redirect
<!DOCTYPE html> <html> <body> <h2>Redirect to a Webpage</h2> <p>The replace() method replaces the current document with a new one:</p> <button onclick="myFunction()">Replace document</button> <script> function myFunction() { location.replace("https://www.w3schools.com") } </script> </body> </html>