Redirect Countdown script [Answered]



The World's Most Misunderstood Programming Language
Ron F

PostTue Mar 20, 2012 10:05 am


User avatar
Rank: Advisor

Posts: 41
Joined: Sun Mar 18, 2012 9:44 pm



Hi Ninja's,

I was looking for a really basic script that will cause a page to redirect to another page. However this needs to happen after a countdown.

I don't know if you have seen those websites that say something along the these lines:

Example:

"you will be redirected in "5" seconds...
If you are not redirected click Here"


does anyone know or have a javascript handy?
alvinGee

PostTue Mar 20, 2012 10:18 am


User avatar
Rank: Helper

Posts: 19
Joined: Wed Feb 29, 2012 11:13 am



Ron F wrote:Hi Ninja's,

I was looking for a really basic script that will cause a page to redirect to another page. However this needs to happen after a countdown.

I don't know if you have seen those websites that say something along the these lines:

Example:

"you will be redirected in "5" seconds...
If you are not redirected click Here"


does anyone know or have a javascript handy?


Hey Ron,

funny you should ask, I do happen to have one handy, probably not the best script in the world and anyho:

HTML:

<h2>You will be redirected in:</h2><h2><span id="mytimer"></span></h2><br/>
If you are not redirected then click <a href="http://www.theitninja.co.uk">here</a>


Javascript Count down Redirect:

   function Redirect(time, url, countdown){
      var c = document.getElementById(countdown);
      time = time -1;
      
      if(c!=null){c.innerHTML = time;}
      
      if(time == 0){
         window.location = url;
      }
      setTimeout("Redirect("+(time)+",'"+url+"','"+countdown+"')", 1000);
   }


then you can simply call this on page load (remember to start of 1 second higher):

Redirect(6, "http://www.theitninja.co.uk", "mytimer");


give that a shot
Ron F

PostTue Mar 20, 2012 10:26 am


User avatar
Rank: Advisor

Posts: 41
Joined: Sun Mar 18, 2012 9:44 pm



alvinGee wrote:then you can simply call this on page load (remember to start of 1 second higher):

Redirect(6, "http://www.theitninja.co.uk", "mytimer");


give that a shot



Hi alvin, when you say call "on page load", sorry how do I this??
Ron F

PostTue Mar 20, 2012 10:29 am


User avatar
Rank: Advisor

Posts: 41
Joined: Sun Mar 18, 2012 9:44 pm



oops! :oops:

just after I posted I released what you talking about, I'm sorry I just had a brain freeze (heh not enough coffee) :D

works great! thank you alvin 8-)
alvinGee

PostTue Mar 20, 2012 10:32 am


User avatar
Rank: Helper

Posts: 19
Joined: Wed Feb 29, 2012 11:13 am



Ron F wrote:just after I posted I released what you talking about, I'm sorry I just had a brain freeze (heh not enough coffee) :D

works great! thank you alvin 8-)


lol :D I hear yea!! man do I need my coffee!

I'm happy that I was able to help you.
dereckT

PostThu Mar 22, 2012 2:29 pm


User avatar
Rank: Junior

Posts: 92
Joined: Tue Feb 28, 2012 1:40 pm



nice little script, also good to see that you have also put in a hardlink.

When doing javascript, its very important to keep in mind "graceful degredation", as this is part of the ethos of the web.
dereckT

PostThu Mar 22, 2012 2:30 pm


User avatar
Rank: Junior

Posts: 92
Joined: Tue Feb 28, 2012 1:40 pm



heh just wanted to add, that I can't do without coffee either!

some say us programmers are just machine that convert coffee into code ;P
Smokey

PostTue May 15, 2012 4:52 am


Rank: Advisor

Posts: 29
Joined: Sun Apr 22, 2012 8:58 pm
Location: NY



A great little Javascript snippet!
8 posts • Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest