Сообщение при не активности мыши и клавиатуры.
Добрый день, друзья.
Подскажите, пожалуйста, как мне реализовать следующее: Цитата:
<script language="javascript"> document.onmousemove = init; document.onkeypress = init; var timeout = null; function init() { if(timeout) { clearTimeout(timeout); timeout = null; } timeout = setTimeout('gt()', 5000); //промежуток } function gt() { location.href = 'test.php'; } </script> Спасибо. |
<div>Осталось времени: <span id="time"></span></div> var init, inis; document.onmousemove = onInit; document.onkeydown = onInit; function onInit() { var a = document.getElementById('time'), b = 5; //Время отсчёта a.innerHTML = ''; if(init) { clearTimeout(init); if(inis) clearInterval(inis); init = 0; inis = 0; } init = setTimeout(function() { inis = setInterval(function() { a.innerHTML = b; b--; if(b < 0) document.location = 'test.php'; }, 1000); }, 5000); } |
Вот это спасибо, почти то что нужно=)
Только как бы сделать так, что бы и "Осталось времени:" появлялось после не активности (в то время когда появляется таймер). |
<div id="time" style="display:none">Осталось времени: <span></span></div> var init, inis; document.onmousemove = onInit; document.onkeydown = onInit; function onInit() { var a = document.getElementById('time'), b = 5, c = a.getElementsByTagName('span')[0] a.style.display = 'none'; if(init) { clearTimeout(init); if(inis) clearInterval(inis); init = 0; inis = 0; } init = setTimeout(function() { a.style.display = ''; inis = setInterval(function() { c.innerHTML = b; b--; if(b < 0) document.location = 'test.php'; }, 1000); }, 5000); } |
Часовой пояс GMT +3, время: 02:28. |