PDA

View Full Version : Reload the page if user isn't typing



M2com
07-09-2012, 05:00 PM
I need a script will reload the page every 10 minutes unless the user is typing. This also means even though the javascript function is in the middle of counting down, the script will restart the "count down" if the user is typing.

Let me know where to start! I've been looking all over and I'm not that great at javascript!

Thanks in advanced!

jscheuer1
07-09-2012, 06:39 PM
<script type="text/javascript">
// No Typing Reload Script (c)2012 John Davenport Scheuer
// as first seen in http://www.dynamicdrive.com/forums/
// username: jscheuer1 - This Notice Must Remain for Legal Use
;(function(){
var addEvent = (function(){return window.addEventListener? function(el, ev, f){
el.addEventListener(ev, f, false);
}:window.attachEvent? function(el, ev, f){
el.attachEvent('on' + ev, function(){f.call(el);});
}:function(){return;};
})(), timer;
function setreset(){
clearTimeout(timer);
timer = setTimeout(function(){location.reload(true);}, 1000 * 60 * 10);
}
addEvent(document, 'keydown', setreset);
setreset();
})();
</script>