Jump to content
xisto Community
Sign in to follow this  
sxyloverboy

Countdown Till Redirect

Recommended Posts

ok here is a question:how would i do something that says you will be redirected in 15 seconds and then changes the number till the redirection takes place. this is planned for a custom 404 error page. im not just asking for the countdown but also how to redirect at all. thankfull for any help :PLucas

Share this post


Link to post
Share on other sites

well, there's a bare-bones html way of redirecting, but you can't display the seconds remaining or anything with it. what you basically do is add this in between the <HEAD> tags.

<meta http-equiv="REFRESH" content="time; URL=your.url">


where time is an integer representing number of seconds until redirect, and your.url is the url that you wish to redirect to.

also html-redirect.html notes that

It is customary to include a direct link to the page that will be switched to automatically in case you get an older browser that doesn't support the feature or the user doesn't want to wait.

i know that there is a way of using a java applet to countdown to 0 and then redirect, but you probably wouldn't want an applet on a 404 error page :P
javascript is probably the way to go for that (although it can be easily disabled- so that's another consideration).

all in all, HTML redirection is probably the most compatible way to do it, and, although it can't do anything really flashy, it gets the job done no problems.

all the best.

Share this post


Link to post
Share on other sites

if you really want it in HTML and java script:

Insert this in the HEAD of you page:

<script language='JavaScript'>var time = 15; //How long (in seconds) to countdownvar page = "yourpage.htm"; //The page to redirect tofunction countDown(){time--;gett("container").innerHTML = time;if(time == -1){window.location = page;}}function gett(id){if(document.getElementById) return document.getElementById(id);if(document.all) return document.all.id;if(document.layers) return document.layers.id;if(window.opera) return window.opera.id;}function init(){if(gett('container')){setInterval(countDown, 1000);gett("container").innerHTML = time;}else{setTimeout(init, 50);}}document.onload = init();</SCRIPT>

And this in the body of the page (where you want the countdown to appear):
<span id='container'></span>

Edited by peroim (see edit history)

Share this post


Link to post
Share on other sites

if you really want it in HTML and java script:
Insert this in the HEAD of you page:

<script language='JavaScript'>var time = 15; //How long (in seconds) to countdownvar page = "yourpage.htm"; //The page to redirect tofunction countDown(){time--;gett("container").innerHTML = time;if(time == -1){window.location = page;}}function gett(id){if(document.getElementById) return document.getElementById(id);if(document.all) return document.all.id;if(document.layers) return document.layers.id;if(window.opera) return window.opera.id;}function init(){if(gett('container')){setInterval(countDown, 1000);gett("container").innerHTML = time;}else{setTimeout(init, 50);}}document.onload = init();</SCRIPT>

And this in the body of the page (where you want the countdown to appear):
<span id='container'></span>

Awesome, this is exactly what I needed :) :) much thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.