Skip to content

Commit fc5c3f9

Browse files
authored
Detect when user is idle
1 parent f662709 commit fc5c3f9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

js/user_idle.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function isIdle() {
2+
var time;
3+
window.onload = notIdle;
4+
window.onmousemove = notIdle;
5+
window.onmousedown = notIdle;
6+
window.ontouchstart = notIdle;
7+
window.onclick = notIdle;
8+
window.onkeypress = notIdle;
9+
window.addEventListener("scroll", notIdle, true);
10+
function userIdle(){
11+
//function to run if user idle
12+
document.write("Idle.........");
13+
}
14+
function notIdle(){
15+
clearTimeout(time);
16+
time = setTimeout(userIdle, 3000); //time idle
17+
}
18+
}
19+
20+
isIdle();

0 commit comments

Comments
 (0)