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! Quote Link to comment https://forums.phpfreaks.com/topic/276207-resetting-countdown-timer/ Share on other sites More sharing options...
Solution haku Posted March 27, 2013 Solution 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(); }); Quote 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. Quote 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. Quote 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! Quote Link to comment https://forums.phpfreaks.com/topic/276207-resetting-countdown-timer/#findComment-1421370 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.