I have worked in capturing the user in the application, after login.
After login I capture the users session with JavaScript's interval functions
The Interval functions trigger every minute.
- when the users session exceeds 1 minute in the app, it should to show a warning message with a count down for the remaining minutes
when the countdown is working properly for the first couple of seconds and then hit the interval function, the count down have a flickering problem.
Session Timeout 3:0 minutes, Here when click the button and after 1 minutes show the countdown will be visible and it reaches some seconds, there have a flickering problem.
Code:
loading= function(){
var lastDigestRun = Date.now();
var idleCheck = setInterval(function () {
alert('interval function invoked');
var now = Date.now();
var displaytime = now - lastDigestRun > 3 * 60 * 1000;
if (now - lastDigestRun > 1 * 60 * 1000) {
alert("warning alert");
load();
}
if (now - lastDigestRun >3 * 60 * 1000) {
alert("logout");
}
}, 60 * 1000);
load = function () {
startTimer(2,0);
function startTimer(m,s)
{
document.getElementById('timer').innerHTML= m+":"+s;
s == 0 ? (m == 0 ? alert('done') : (m--, s=60, t())) : (s--, t());
function t(){ setTimeout(function(){startTimer(m,s)},1000)};
}
};
Please also look at this JSFiddle