Go Premium for a chance to win a PS4. Enter to Win


Permanent VARIABLES and "Smart Countdown" ?

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

Question by:ljaques

Expert Comment

ID: 1272402
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
ID: 1272403
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

ID: 1272404
Adjusted points to 5

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

971 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