We help IT Professionals succeed at work.

Permanent VARIABLES and "Smart Countdown" ?

ljaques asked
Medium Priority
Last Modified: 2008-03-06
I have created a small program which shows the minutes left to the top of the hour (ie. if it's 9:34pm right now, the count down show: 00:26 mins left).  I used the <IMG> command to call my CGI script which sends back binary data of a GIF picture corresponding to the correct digits of the minutes left.  So it looks like I have a "graphical" countdown of the minutes left.  

I use Javascripting to call a function every 1 minute.  In this function it makes a recall to my CGI script to get the *present* minutes left.  This way the counter is counting down graphically every minute.  

I want the user of my web site to have the ability to refresh the screen, leave my web site and BACK up to it at a later time, and to ALWAYS see my countdown at the EXACT minutes left before the hour.  I achieved this with always calling my CGI script to get the latest minutes left.  Unfortunately, I want ONE more thing.  I want the countdown to countdown to 00:00 and never go past this!  As soon as it hits 00:00 it pops up a new graphic to tell user to RELOAD the web page since it is old.  

Now if the user is allowed to leave my web site and is allowed to back up to see the NEW minutes left before the hour, he could leave my web site for DAYS and then back up to it seeing the new minutes left before the hour, but 00:00 of the hour he really came in had long passed.  The graphic that should pop up would never pop up until 00:00 is reached for this hour.

Is there anyway I can use a PERMANENT VARIABLE in Javascripting (persists even if the user leaves my web site) which can store some useful data to solve this problem?  Or is there another trick I can use to make sure the user gets the graphic: RELOAD THIS WEB PAGE, because the end of the hour when you arrived has lapsed?????

Watch Question

The "permanent variable" you refer to exist- cookies. You can read and write cookies from javascript. You can also read and write cookies from a .pl. When your script returns a countdown digit it could set a cookie that gives the time to pop up the "reload" message. Whenever the countdown digits are loaded, if the cookie sees the "reload" message time is past it could send the reload graphic.

Be aware though that a lot of people hate cookies and have them turned off, so this won't always work and will annoy some people. I haven't checked whether the "ask before accepting cookie" flag applies to javascript too, though I would assume so.

If your entire page is produced by a script, you could set the expires time to the top of the hour, which is probably a cleaner way of handling this.

let me know when you get some points :-)
Another option is to use Perl script to save var value to file on a server but you'll need to associate every such file with the user (I would use his IP address for that). Advantage - no need for cookies and, therefore, reliability, because you don't have to depend on users acceptence of the cookie. Disadvantage - number of files can grow indefinitely. The whole thing will take just coule of lines in perl.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Adjusted points to 5
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.