I tryed to use this code to auto logout after 15 mins.
But this doesnt work properly. I leave my comp for 15mins, but nothing happend. It remains logged in.
But on the other hand, if i try shorter time, for an example 5s it works perfect…after 5s it logged me off.
I don’t know, where is problem/bug?
var int=self.setInterval(setLastAction,1000);
function setLastAction(){
var lastAction = new Date();
var baz = new Date();
baz.setTime(lastAction.getTime() - firstAction.getTime());
baz = baz.getSeconds();
if(baz >= (15*60)){
logOut();
}
}
$(document).mousemove(function(){
firstAction = new Date();
});
You are getting the seconds from a
Dateobject, usinggetSeconds(), which will always return an integer between0and59. Compare the difference between the times instead of creating a newDateobject: