Таймер при клике на ссылку
Доброго всем Здравия!
Нашел в интернете скрипт, который может запускать таймер с открытием странички после нажатия на кнопку. Но, после обновление странички с таймером, он сбрасывается... Помогите, пожалуйста, сохранить значение таймера при обновление странички и после перезагрузки браузера! <!DOCTYPE html> <html> <head> <title>111</title> <meta charset="utf-8"> <style> .st{background-color:blue; color:white;} .sp{background-color:red; color:white;} </style> </head> <body> <table border="0" cellpadding="0" cellspacing="0" bordercolor="#00000"> <tr><td><div class="st" id="tm">01:20:20</div></td></tr></table> <input type="button" value="старт" onclick="timer.start(),Sl()" > <input type="button" value="стоп" onclick="timer.stop()"> </body> </html> var Timer = function(element, hours, minutes, sec){ var me = this; this.hours = hours; this.minutes = minutes; this.sec = sec; this.element = element; this.interval = null; this.reduce = function() { if(me.hours + me.minutes + me.sec <= 0) { me.stop(); return; } me.sec-=1; if(me.sec<0) me.sec=00,me.minutes-=1; if(me.minutes<0) me.minutes=00,h-=1; if(me.hours<0) me.hours=00 ; if(me.hours + me.minutes + me.sec==0)me.callback(); me.sec = me.sec+""; me.minutes = me.minutes+""; me.hours = me.hours+""; if (me.sec.length<2) me.sec = "0"+me.sec; if (me.minutes.length<2) me.minutes = "0"+me.minutes; if (me.hours.length<2) me.hours = "0"+me.hours; me.element.innerHTML=me.hours+":"+me.minutes+":"+me.sec; } this.start = function(){ me.interval = setInterval(me.reduce, 1000); me.element.className="sp" } this.stop = function(){ clearInterval(me.interval); me.element.className="st" } } var timer = new Timer(document.getElementById('tm'), 1, 20, 20); function Sl() {window.open('https://mail.ru/','_blank');} |
Часовой пояс GMT +3, время: 07:04. |