John Van Meenen

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromJohn Van Meenen
ToMe
Subjectcookie based dhtml progress bar
Date30 June 2009 13:43
Dear Mr. Wilton-Jones,

I searching a way to get  info from a cookie (expire date - actual time)
and pars it to a graphical progress bar (dhtml) to display a status from
100% to 0%.
Each cookie will have different expire dates.
What I want to achive is a maintenance overview that a user will see in a
scheduled task (this dhtml document) that will pop up every working day of
the week.
There are about 20 maintenance tasks to be executed on different
frequenties, some are daily, weekly, 2 weekly, monthly etc..
i.e. the corona of the press needs to be cleaned every 2 weeks.
By having the dhtml file in the scheduled task the operator will have
directly an overview of the to be executed maintenance tasks.
Besides each task a button must be present to reset the cookie expire date
(when task has been executed).
The user can also close the dhtml file, but the cookies need to be there
when the dhtml file is loaded again the next day af the working week.
This should run on a computer next to the printing press and is only
dedicated to this press.
The operating system is 2003 server and it is using inetrnet explorer 6.

I was searching on the internet, but calculating time from an expire date
of a cookie is hard to find.
I am a novice in scripting, al help will be welcome.

Regards,
John
FromMe
ToJohn Van Meenen
SubjectRe: cookie based dhtml progress bar
Date8 July 2009 13:28
John,

> I searching a way to get  info from a cookie (expire date - actual time)
> and pars it to a graphical progress bar (dhtml) to display a status from
> 100% to 0%.

Well, you can't get the cookie's own expiry date - that information is not
exposed to either the server or JavaScript. However, you can store any
string information in a cookie, so you can store a string or integer
representing that date (in milliseconds) in the cookie.

Assuming you are using my cookie script to simplify cookie setting and
retrieval:
http://www.howtocreate.co.uk/jslibs/script-cookie
For example:
setCookie('coronaclean','1247037519484');

Then to retrieve it and work out how much time is left, simply construct a
new Date object to get the current datestamp as a number:
var timeleft = (new Date()).getTime() - retrieveCookie('coronaclean');

Applying this to a progress bar would be a simple case of taking the maximum
lifetime (one week or whatever) and dividing the time left by that number of
milliseconds:

var portionremaining = timeleft / 604800000;

This gives you a number like 0.342576 which you can then multiply by
whatever you needed to set the width of your progress bar (or feed it
directly into my progress bar script).

The Date object also offers the useful .parse() method to help convert human
readable date strings into timestamps.

var mytimestamp = Date.parse('Wed Jul 08 2009 08:22:56 GMT+0100');

> using inetrnet explorer 6

You have my most sincere condolences. Best of luck with that.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.