Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

Countdown Till Redirect


6 replies to this topic

#1 sxyloverboy

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 302 posts
  • Location:Frankfurt, Germany

Posted 06 December 2005 - 07:18 PM

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 :P

Lucas

#2 rvalkass

    apt-get moo

  • [MODERATOR]
  • PipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPipPip
  • 3,107 posts
  • Gender:Male
  • Location:Devon, England
  • Interests:At the moment, Physics mainly!
  • myCENT:69.42
  • Spam Patrol

Posted 06 December 2005 - 08:11 PM

This should do something similar to what you need. Simply cut and paste it and change the few settings.

http://javascriptkit...tredirect.shtml

#3 sxyloverboy

    Super Member

  • Kontributors
  • PipPipPipPipPipPipPipPipPip
  • 302 posts
  • Location:Frankfurt, Germany

Posted 06 December 2005 - 09:13 PM

yeah thats pretty much what i mean. but i dont really like the form thing that shows the number? is there maybe a way to get a number that looks like its in the text?

#4 switch

    Premium Member

  • Kontributors
  • PipPipPipPipPipPipPipPip
  • 178 posts
  • Location:NSW, Australia
  • Interests:music,<br />3d graphics programming.

Posted 06 December 2005 - 10:34 PM

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 www.billstclair.com/html-redirect2.html notes that

Quote

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.

#5 peroim

    Newbie [Level 2]

  • Kontributors
  • PipPip
  • 33 posts
  • Gender:Male
  • Location:Belgium

Posted 11 July 2006 - 10:50 AM

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 countdown
var page = "yourpage.htm"; //The page to redirect to
function 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, 11 July 2006 - 10:56 AM.


#6 swift29

    Newbie

  • Kontributors
  • Pip
  • 1 posts

Posted 16 June 2010 - 06:36 AM

hi im new here but i would just like to say it took me ages to find this and yours was the best one so thanks, but how do you change the colour of the countdown

#7 Guest_Anyonymous_*

  • Guests

Posted 06 April 2011 - 09:36 PM

View Postperoim, on 11 July 2006 - 10:50 AM, said:

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 countdown
var page = "yourpage.htm"; //The page to redirect to
function 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




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users