javascript - continue looping after alert message -
below function use check session of page. page reload after clicked alert message.
var timeleft = 60; function checktime() { timeleft--; if (timeleft == 30 ) { alert("30 secs left."); window.location.reload(); } }
is there anyway timeleft continue minus (if user din't not notice alert message) redirect logout page when timeleft = 0.
alert()
modal, stops javascript execution. check code:
var start = new date(); var start2; window.settimeout(function() { var end = new date(); var result = "time start: " + (end.gettime() - start.gettime()) result += "\ntime alert: " + (end.gettime() - start2.gettime()) result += "\nalert open for: " + (start2.gettime() - start.gettime()) alert(result); }, 500); window.settimeout(function() { alert("hello"); start2 = new date(); }, 100);
fiddle upper code: http://jsfiddle.net/aorcsik/vfeh2/1/
check out code, shows settimeout stopped during alert()
, can check how time user looking @ alert, , update counter (timeleft
) decreasing measured time devided ticker delay.
solution: solution measure how time user looks @ alert modal, , whenever clicks ok, check if session ended, if yes redirect logout, else usual redirect.
var start = new date(); alert("xxx"); var t = (new date()).getdate() - start.getdate(); if (t / 1000 > timeleft) { /* logout */ } else { /* redirect */ }
note: solution use html popup instead of javascript alert, not block javascript execution
Comments
Post a Comment