Question

I am baffled. I have a "ready" function, from jQuery, which sets an HTML5 sessionStorage variable to the .valueOf() result of a new Date (as shown below). Somehow, though, the variable keeps refreshing and updating the time while my page is open. The sessionStorage variable doesn't even know it's a Date, it just stores the milliseconds, and the "ready" function is only called once at the beginning (I've checked using an alert window). There is no logic in my code to make this happen, but the value on the page stays up-to-date in real time. Any ideas?

// Initialize default date range
if (sessionStorage.minDate == null) {
    d = new Date();
    sessionStorage.minDate = (d.valueOf() - 172800000);
    delete d;
}
if (sessionStorage.maxDate == null) {
    d = new Date();
    sessionStorage.maxDate = d.valueOf();
    delete d;
}

UPDATE: Still not fixed, but I've tried giving the milliseconds as a literal, and it still does the same thing. So it must have something to do with the fact that I'm creating a new Date later on using the millisecond count.

Any thoughts are much appreciated. I really have to get this working for work.

Was it helpful?

Solution

Apparently I was storing the number of milliseconds as a string, and wasn't parsing it back into an integer, so when I tried to create a new Date with it, javascript didn't know what to make of it and just created a Date with no parameters: the current date and time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top