I need to check more how many days have passed since a certain date and reduce the number of days of the counter. Mostly just because I did not expect anyone to leave the same page open unnecessarily or want to reload for several days in a row. I would do something like this:
counter = 365; // original counter var start = new Date(2016, 03, 20); // original date var now = new Date(); var days = Math.floor(Math.abs(start.getTime()-now.getTime())/(24*60*60*1000)) counter -= days;
Thus, every time you visit a page, it will decrease correctly. Please note that this ignores any problems with the temporal days or time zones. In the above example, there will be a 360 counter for me. And if you expected it to be open in a few days, restart it automatically:
self.setTimeout(function(){document.location.reload()}, 86400000);
jdgregson
source share