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.
Asked
Active
Viewed 686 times
2 Answers
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>
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
-
@RichyChai Oh, sorry, I will update my answer now. You should place it in your `head` tag. – Yeldar Kurmangaliyev Dec 02 '15 at 04:40