I want my users to see one confirm box after say 15 min,alerting them about the session timeout.I want this process to continue repeatedly. That is even if the user selects cancel from the confirm box he will get the same alert after 15 min.
I want my users to see one confirm box after say 15 min,alerting them about the session timeout.I want this process to continue repeatedly. That is even if the user selects cancel from the confirm box he will get the same alert after 15 min.
Share Improve this question asked Nov 2, 2010 at 7:16 Hector BarbossaHector Barbossa 5,52813 gold badges50 silver badges70 bronze badges 1- 1 Yep, just click the little check mark next to the best answer. It makes folks want to answer you more. – rwilliams Commented Nov 2, 2010 at 7:57
5 Answers
Reset to default 5You could use the setInterval function if you want it to run repeatedly:
setInterval(function() {
alert('hello world');
}, 15 * 60 * 1000);
Also you might take a look at the jquery idleTimer plugin which allows you to detect periods of user inactivity and take some actions.
setInterval(alert(Session Timeout),90000);
for confirm box
setInterval(alert(confirm('Session Timeout')),90000);
You have two options
setInterval(f,ms)
function f() {
confirm('Session Timeout')
}
setInterval(f, 15 * 60 * 1000);setTimeout(f,ms) + recursion
function f() {
confirm('Session Timeout')
if ( ! stopCondition ) setTimeout(f, 15 * 60 * 1000);
}
setTimeout(f, 15 * 60 * 1000);
Conclusion :
setInterval is better when you want the behavior to repeat forever
setTimeout is better when you want to stop the behavior later
Use setInterval for this
var t = setInterval("alert('Your sesssion will be expired after 15 min')",900000);
just use setTimeout()
:
function handleSessionTimeout() {
var isOk = confirm("Your session is going to time out");
if( isOk ) {
// let the session time out
} else {
// don't let it timeout.
// restart the timer
setTimeout(handleSessionTimeout, 900000);
}
}
setTimeout(handleSessionTimeout, 900000);
the times (900000
) are in milliseconds.