javascript - Session Timeout - results in minutes -


this question has answer here:

var idle_timeout = 2700; //seconds 45min    var _idlesecondscounter = 0;  document.onclick = function() {    _idlesecondscounter = 0;  };  document.onmousemove = function() {    _idlesecondscounter = 0;  };    document.onkeypress = function() {    _idlesecondscounter = 0;  };  window.setinterval(checkidletime, 1000);    function checkidletime() {    _idlesecondscounter++;    var opanel = document.getelementbyid("secondsuntilexpire");    if (opanel)      opanel.innerhtml = (idle_timeout - _idlesecondscounter) + "";    if (_idlesecondscounter >= idle_timeout) {      //alert("your session time expired. please login.");      document.location.href = "logoff.php";    }  }
<div id='secondsuntilexpire'></div>

so above getting output 2699 ( in seconds = 45min ) , if no event happen decrements ( 2698..2697..and on ) , if event (mouse up..etc ) happen 2699

but need in minutes thats : 44:59, 44:58 ..and on

here's how i'd code readable

function checkidletime() {     _idlesecondscounter++;     var opanel = document.getelementbyid("secondsuntilexpire");     var remain = idle_timeout - _idlesecondscounter;     var remainminutes = math.floor(remain / 60);     var remainseconds = ('0' + (remain % 60)).substr(-2);     if (opanel)         opanel.innerhtml = remainminutes + ':' + remainseconds;      if (_idlesecondscounter >= idle_timeout) {         //alert("your session time expired. please login.");         document.location.href = "logoff.php";     } } 

uses

var remainseconds = ('0' + (remain % 60)).substr(-2); 

so seconds 2 digits


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -