Мне нужна помощь для хранения времени для этого таймера обратного отсчета, он работает нормально, но когда я нажимаю кнопку «Обновить» или назад в браузере, таймер запустит его снова, например, в 15:00, затем в примере запуска таймера будет 9:00, если янажмите обновить, он вернется к 15:00.
(function() {
function display(notifier, str) {
document.getElementById(notifier).innerHTML = str;
}
function toMinuteAndSecond(x) {
return ~~(x / 60) + ":" + (x % 60 < 10 ? "0" : "") + x % 60;
}
function setTimer(remain, actions) {
var action;
(function countdown() {
display("countdown", toMinuteAndSecond(remain));
if (action = actions[remain]) {
action();
}
if (remain > 0) {
remain -= 1;
setTimeout(arguments.callee, 1000);
}
})(); // End countdown
}
setTimer(900, {
120: function() {
display("notifier", "Just 1 minute to go");
},
50: function() {
display("notifier", "50 seconds left");
},
}
}
);
})();
<span id="notifier"></span>