Set the href value to point to another web site:
location.href = "https://www.java2s.com";
Click the button to set the href value to https://www.java2s.com.
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Take me to java2s.com</button> <script> function myFunction() {//from w w w . j a va2s. co m location.href = "https://www.java2s.com"; } </script> </body> </html>