lilmer Posted March 27, 2013 Share Posted March 27, 2013 Hello good day, I've got here a code for countdown: var times = 50; function startCountdown() { if((times - 1) >= 0){ times = times - 1; $("#refreshTime").html('Auto logout: ' + times); setTimeout(startCountdown, 1000); }else{ //alert('Your session has ended!'); } } But my problem is, I got no idea on function that will reset the time when some click or hover the html body page. Thanks and regards! Link to comment https://forums.phpfreaks.com/topic/276207-resetting-countdown-timer/ Share on other sites More sharing options...
haku Posted March 27, 2013 Share Posted March 27, 2013 Since you are using jQuery: var times = 50, timer; function startCountdown() { if((times - 1) >= 0){ times = times - 1; $("#refreshTime").html('Auto logout: ' + times); timer = setTimeout(startCountdown, 1000); }else{ //alert('Your session has ended!'); } } function resetTimer() { clearTimeout(timer); } $(document).scroll(function() { resetTimer(); }); $(document).keydown(function() { resetTimer(); }); $(document).mousemove(function() { resetTimer(); }); Link to comment https://forums.phpfreaks.com/topic/276207-resetting-countdown-timer/#findComment-1421321 Share on other sites More sharing options...
lilmer Posted March 27, 2013 Author Share Posted March 27, 2013 Thanks but it only stop the time but not resetting it. Link to comment https://forums.phpfreaks.com/topic/276207-resetting-countdown-timer/#findComment-1421333 Share on other sites More sharing options...
haku Posted March 27, 2013 Share Posted March 27, 2013 So reset it after the line where it's being stopped. I helped you with the hard part, that's the easy part. Link to comment https://forums.phpfreaks.com/topic/276207-resetting-countdown-timer/#findComment-1421334 Share on other sites More sharing options...
lilmer Posted March 27, 2013 Author Share Posted March 27, 2013 Thanks Mr. Guru! Link to comment https://forums.phpfreaks.com/topic/276207-resetting-countdown-timer/#findComment-1421370 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.