How can I fetch the system idle time using by browser. Is there an implemented solution for this scenario .
Asked
Active
Viewed 321 times
0
-
2https://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly#4029518 – 4b0 Jan 18 '18 at 03:56
-
2Possible duplicate of [Detecting idle time in JavaScript elegantly](https://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly) – Ayush Gupta Jan 18 '18 at 04:10
1 Answers
0
Use below code:
var idleTime = 0;
var allowedIdleTime = 2000;
$(document).ready(function () {
var idleInterval = setInterval(calculateTime, 1000); // 1 second
$(window).focus(function (e) {
if(idleTime>allowedIdleTime) {
console.log('Last Idle Time was ' +idleTime+' ms' );
}
});
$(window).blur(function (e) {
idleTime = 0;
});
});
function calculateTime() {
idleTime = idleTime + 1000;
}
Here allowedIdleTime
time can be set to avoid calling target operation before a specified interval.

jeet427
- 538
- 3
- 16
-
Hi Jeet, Your answer for get idle time while we are not moving the mouse and keyboard within webpage document. But I need solutions for while I work with some other active window like notepad,Terminal or IDE ..etc . I need to fetch that idle time from browser – Selvakumar M Jan 18 '18 at 04:47