Timed Redirect with JavaScript
Sometimes a person wants a web page to load a different web page after a certain amount of time. Perhaps after a movie or sufficient time to appreciate a splash page.
This article presents a JavaScript method. See Timed Redirect with Meta Refresh for a meta refresh method.
Determine:
-
How many seconds to wait after the web page has loaded before loading the next web page.
-
The URL of the web page to load after the number of seconds have elapsed.
The JavaScript belongs at the bottom of the web page source code, above the cancel </body> tag. This is the format:
<script type="text/javascript"><!-- var seconds = __A__; var url = "__B__"; setTimeout("window.location='"+url+"'",seconds*1000); //--></script>
Replace __A__ with the number of seconds to wait. And replace __B__ with the URL of the web page to load.
For example, to load the https://www.willmaster.com/index.php web page 25 seconds after the first page has loaded, this JavaScript tag will accomplish it:
<script type="text/javascript"><!-- var seconds = 25; var url = "https://www.willmaster.com/index.php"; setTimeout("window.location='"+url+"'",seconds*1000); //--></script>
Put the JavaScript at the bottom of the web page source code, above the cancel </body> tag. In that position, the timer will not start until the browser has loaded the souce code up to that point.
The timer still might start before all media has loaded. If that may be an issue with site visitors' varying Internet connection speeds, consider the Timed Redirect with Meta Refresh method.
Will Bontrager