Reputation: 234
I have an application that requires a login and I also have an AJAX timer. I have read several posts on how to create a session timeout after a certain period of time. However, I want the session to end if the user hasn't clicked a certain button for say, 5 minutes. Is there a way to reset the timer after every click?
Upvotes: 1
Views: 1424
Reputation: 78880
Try this:
function logout() {
location.href = '/your/logout/page.aspx';
}
var timeout = setTimeout(300000, logout);
function resetTimeout() {
clearTimeout(timeout);
timeout = setTimeout(300000, logout);
}
document.onclick = resetTimeout;
Upvotes: 3
Reputation: 14233
You could setup a javascript timer on the page load (with setTimeout) and that would get reset with each post-back (and optionally by a button click that does NOT post back), and when that timer counts down to zero it would redirect to a logout.aspx (ex: window.location='Logout.aspx') that handles clearing the session and then redirects back to the Login page.
Upvotes: 0