How to make a redirect page with javascript?

Member

by bertha , in category: SEO , a year ago

How to make a redirect page with javascript?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by dejuan.watsica , a year ago

@bertha 

To redirect a page using JavaScript, you can use the window.location object which represents the current URL address of the browser. Here is an example of how you can make a redirect page using JavaScript:

1
2
3
4
5
6
7
8
9
<script>
  // Redirect function
  function redirectTo(url) {
    window.location.href = url;
  }

  // Call the redirect function with the desired URL
  redirectTo("https://www.example.com");
</script>


In the example above, the redirectTo function takes a URL as a parameter and assigns it to window.location.href. As a result, the browser navigates to the specified URL, effectively redirecting the page. Simply replace the URL inside the redirectTo function with your desired destination.