I have this Javascript below. It counts up (it says Countdown but it's been modified to "countup" now from 00). But when the browser has been refreshed or come back to the page, then the counter starts from 00 again. Is there a way to add a cookie to it or some other code so that it remembers the count it was at for the session someone is browsing a site?
<script type="text/javascript">
function pad(num, size) {
var s = num + "";
while (s.length < size) s = "0" + s;
return s;
}
function initCountdown() {
setTimeout(function() {
current_wait++;
if (current_wait <= waits.length) {
var countdowns = document.getElementsByClassName('countdown');
for (var i = 0; i < countdowns.length; i++) {
var number = parseInt(countdowns[i].innerHTML);
number++;
countdowns[i].innerHTML = pad(number, 2);
}
initCountdown();
}
}, waits[current_wait] * 1000);
}
var initial_number = 0;
var waits = [2, 8, 16, 26, 44, 66, 88, 99, 121]; //t-val
var current_wait = 0;
var countdowns = document.getElementsByClassName('countdown');
for (var i = 0; i < countdowns.length; i++) {
countdowns[i].innerHTML = pad(initial_number, 2);
}
initCountdown();
</script>