jose-m
12/21/2017 - 7:02 PM

SESSION DE INACTIVIDAD

SESSION DE INACTIVIDAD EN APLICACION

document.addEventListener('DOMContentLoaded', function(){
  countDown();
  addEvents();
});
var totalMinutes = 4;
var totalSeconds = 60;
var timeOut;
function addEvents() {  
  window.addEventListener('mousemove', function(){
    resetCountDown();
  });
  window.addEventListener('onkeypress', function(){
    resetCountDown();
  });
  
}
function resetCountDown(){
  totalMinutes = 4;
  totalSeconds = 60;
}
function countDown() {  
  totalSeconds = totalSeconds - 1;  
  if (totalSeconds < 0) {
    totalSeconds = 59;
    totalMinutes = totalMinutes - 1;
  } 
  if(totalMinutes === 0 && totalSeconds === 0) {
    alert('La sesion ha expirado.');
    clearTimeout(timeOut);
    top.location.replace(getUrl());
    window.location.href = getUrl();
    return;
  }
  timeOut = setTimeout("countDown()",1000);
}
function getUrl() {
  var urlArray = window.location.href.split('/');
  return urlArray[0] + '//' + urlArray[2] + '/tirasauditorasWeb/LogOut.do';   
}