Permanent VARIABLES and "Smart Countdown" ?

Posted on 1997-11-03
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?????

Question by:ljaques

Expert Comment

Comment Utility
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 :-)

Accepted Solution

malec earned 0 total points
Comment Utility
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.

Author Comment

Comment Utility
Adjusted points to 5

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
indexOf() 2d array value 2 38
Need to learn promise API 2 27
Safari SVG Image Problem 1 19
Cordova Camera plugin fails 2 5
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now