Skip to content

Instantly share code, notes, and snippets.

@danielt69
Created July 7, 2016 07:28
Show Gist options
  • Save danielt69/6e04c842cc97c508934516644bf87d8d to your computer and use it in GitHub Desktop.
Save danielt69/6e04c842cc97c508934516644bf87d8d to your computer and use it in GitHub Desktop.
How to Detect user is active or idle on web page Using JQuery ? From https://arjunphp.com/detect-user-is-active-or-idle-on-web-page-using-jquery/
$(document).ready(function () {
var idleState = false;
var idleTimer = null;
$('*').bind('mousemove click mouseup mousedown keydown keypress keyup submit change mouseenter scroll resize dblclick', function () {
clearTimeout(idleTimer);
if (idleState === true) {
$("body").css('background-color','#fff');
}
idleState = false;
idleTimer = setTimeout(function () {
$("body").css('background-color','#000');
idleState = true; }, 2000);
});
$("body").trigger("mousemove");
});
// - See more at: https://arjunphp.com/detect-user-is-active-or-idle-on-web-page-using-jquery/#sthash.p4P2lGUP.dpuf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment