20

I need one of my website pages to instantly redirect to another upon loading. The refresh HTML command does not work, as it does not check whether or not a certain url is being loaded. Also javascript will work too.

Dharman
  • 26,923
  • 21
  • 73
  • 125
Matthew
  • 322
  • 2
  • 3
  • 12
  • 1
    An example of what you have tried? So you want the page to load and then redirect or do you want an instant redirect? – NewToJS Sep 30 '17 at 00:53
  • 3
    Possible duplicate of [Redirect from an HTML page](https://stackoverflow.com/questions/5411538/redirect-from-an-html-page) – icecub Sep 30 '17 at 01:02
  • 1
    Does this answer your question? [How do I redirect to another webpage?](https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage) – mhrabiee Dec 04 '19 at 11:12

2 Answers2

40

You can wait for a load event with JavaScript and use one of either:

window.onload = function() {
    // similar behavior as clicking on a link
    window.location.href = "http://stackoverflow.com";
}

or

window.onload = function() {
    // similar behavior as an HTTP redirect
    window.location.replace("http://stackoverflow.com");
}

Source: How to redirect to another webpage?

DavSanchez
  • 777
  • 6
  • 12
35

Just add a meta tag in the head section of your HTML like this:

<html>
  <head>
    <meta http-equiv="refresh" content="0;url=http://redirect-to-this-page.com" />
    <title></title>
  </head>
 <body></body>
</html>
Jacman
  • 1,370
  • 3
  • 18
  • 30