-1

How would I redirect from a page using HTLM with a certain delay? For example I would go onto a webpage, and after 5 seconds the page would redirect.

2 Answers2

3

You're probably looking for the meta refresh tag:

<html>
    <head>
        <meta http-equiv="refresh" content="5;url=http://www.somewhere.com/" />
    </head>
    <body>
        <h1>Redirecting in 5 seconds...</h1>
    </body>
</html>

Source: Redirect website after certain amount of time

Community
  • 1
  • 1
Suyog
  • 2,472
  • 1
  • 14
  • 27
1

You can use HTML meta tag. It will redirect to another page. The countdown is started right after this page is loaded:

<html>
  <head>
    <META http-equiv="refresh" content="5;URL=http://example.com">
  </head>
</html>

where "5" stands for 5 seconds. You can set 0 to redirect instantly.

It is the best way as it doesn't require JavaScript and it is supported by all modern browsers.

If you want to do this not after page loading, but after some action, you will need to use JavaScript window.location.href property and setTimeout for delaying this action:

setTimeout(function() {
    window.location.href = "http://example.com";
}, 5000); 

where 5000 means 5000 ms (i.e. 5 seconds).

Yeldar Kurmangaliyev
  • 33,467
  • 12
  • 59
  • 101