setinterval - jquery check every 2 minutes if there was a click or mousemove event -
i need refresh page after 10 minutes of inactivity.
what mean inactivity : no mouse move and/or no clicks on body
here's have far (that piece of code working fine)
idletime = 0; function timerincrement() { idletime = idletime + 1; if (idletime > 10) { window.location.reload(); } } $j(document).ready( function(e) { var idleinterval = setinterval("timerincrement()", 60000); // 1 min $j(this).mousemove(function () { idletime = 0; }); $j(this).click(function () { idletime = 0; }); }
what dont here, fact reseting timer on every single mousemove event. , im worried performance.
what : check every 2 minutes if mouse position changed. if yes increment timer. not sure how that.
any help?
you add flag variable (eg: hasmousemoved, update on mousemove hander , remove event handler, whenever timer fires change code to:
if ((idletime > 10) || (idletime%2==0 && hasmousemoved)) { window.location.reload(); }
Comments
Post a Comment