HTML redirect on page load

Viewed 83481

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.

2 Answers

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?

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>
Related