Quantcast
Channel: How to redirect one HTML page to another on load - Stack Overflow
Viewing all articles
Browse latest Browse all 51

Answer by RafaSashi for How to redirect one HTML page to another on load

$
0
0

This is a sum up of every previous answers plus an additional solution using HTTP Refresh Header via .htaccess

  1. HTTP Refresh Header

    First of all, you can use .htaccess to set a refresh header like this

    Header set Refresh "3"

    This is the "static" equivalent of using the header() function in PHP

    header("refresh: 3;");

    Note that this solution is not supported by every browser.

  2. JavaScript

    With an alternate URL:

    <script>    setTimeout(function(){location.href="http://example.com/alternate_url.html"} , 3000);</script>

    Without an alternate URL:

    <script>    setTimeout("location.reload(true);",timeoutPeriod);</script>

    Using the window object:

    <script>    window.location.reload(true);</script>
  3. Meta Refresh

    You can use meta refresh when dependencies on JavaScript and redirect headers are unwanted

    With an alternate URL:

    <meta http-equiv="Refresh" content="3; url=http://example.com/alternate_url.html">

    Without an alternate URL:

    <meta http-equiv="Refresh" content="3">

    Using <noscript>:

    <noscript><meta http-equiv="refresh" content="3" /></noscript>

Optionally

As recommended by Billy Moon, you can provide a refresh link in case something goes wrong:

If you are not redirected automatically: <a href='http://example.com/alternat_url.html'>Click here</a>

Resources


Viewing all articles
Browse latest Browse all 51

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>