Jump to content

Resetting countdown Timer.


lilmer

Recommended Posts

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

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();
});

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.