condpattern,
<script src="http://learn.javascript.ru/files/tutorial/browser/cookie/cookie.js"></script>
<script>
function clickTimer() {
if (!d) {
d = new Date().setHours(24, 0, 0, 0);
setCookie('timestamp', d, { expires: d, path: '/' });
startTimer();
}
}
function startTimer() {
var a = d;
var b = new Date();
var c = a - b;
if (a >= b) {
var h = parseInt(c / 36e5) % 24;
if (h < 10) h = '0' + h;
var m = parseInt(c / 6e4) % 60;
if (m < 10) m = '0' + m;
var s = parseInt(c / 1e3) % 60;
if (s < 10) s = '0' + s;
e.innerHTML = h + ' : ' + m + ' : ' + s;
setTimeout(startTimer, 1e3);
} else {
d = 0;
deleteCookie('timestamp');
e.innerHTML = 'Click Me';
}
}
</script>
<div id="countdown">Click Me</div>
<script>
var d = getCookie('timestamp');
var e = document.getElementById('countdown');
e.onclick = clickTimer;
if (d) startTimer();
</script>
|