简体   繁体   中英

User logout warning and auto timeout

I have a page that alerts user every 10 seconds whether he wants to stay logged in or not. If he chooses yes, he will stay logged in and the timer runs again and he is alerted after another 10 seconds. If no, he is logged out immediately.

Here is the JSFiddle of the below code.

<script>
(function dimer()
{
setTimeout(function()
{
var x=window.confirm("Session is about to time-out !!! Press OK to Continue - CANCEL to logout !!!")
if (x){
dimer();
auto();
}
else
{
window.location.href = '../logoff.php';
}
},10000);
})()
</script>
<script>
function auto()
{
setTimeout(function()
{
alert("You have been logged out.");
window.location.href = '../logoff.php';
},20000);
}
</script>

What happens is when i click yes, the dimer and auto functions run and again after 10 secs i get prompt. If i again click yes, and after 10 secs i should again get the prompt but whereas i get the expired warning.

I hope you are trying to alert it every 10 sec. Use

setInterval(functionName,interval);

instead of setTimeout()

Hope this help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM