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.
Asked
Active
Viewed 9.7k times
25
-
1An 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
-
3Possible duplicate of [Redirect from an HTML page](https://stackoverflow.com/questions/5411538/redirect-from-an-html-page) – icecub Sep 30 '17 at 01:02
-
1Does 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 Answers
44
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,486
- 3
- 20
- 32
43
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");
}

DavSanchez
- 831
- 8
- 13