Update @ 2016-05-21: Please consider using the idleCat plugin instead of this brute force checking approach. Thanks for the suggestion from Smuuf. =D
–
Nowadays, websites are becoming more advanced with many different features. Sometimes it would be beneficial if we could switch off them on the client browser when the user is idle for a period of time in order to reduce the web server loading.
Here is a Javascript example which would pop up an alert box if the mouse doesn’t move for 3 mins.
$(document).ready(function () { // Set timer to check if user is idle var idleTimer; $(this).mousemove(function(e){ // clear prior timeout, if any window.clearTimeout(idleTimer); // create new timeout (3 mins) idleTimer = window.setTimeout(isIdle, 180000); }); function isIdle() { alert("3 mins have passed without moving the mouse."); } });
Done =)
Reference: StackOverflow – Detecting idle time in JavaScript elegantly
Whoa, doing this for EVERY mouse move event generated by the browser sounds like a really expensive thing to do. I would argue that doing this only when N have seconds passed is a more appropriate way to do.
As it is done in the jQuery plugin idleCat: https://github.com/smuuf/jquery-idlecat … Disclaimer: I’m the author of the plugin.
LikeLike
Thanks for your suggestions. =D
LikeLike
window or document.addEventListener(“mousemove”, ()) is not working in my project, basically, half part of the project is made in react and half in angular,
if m using “window or document.addEventListener(“mousemove”, ())” in angulat then this works for angular part only and same for the react also, so can anyone plz help
LikeLike