Dr. Rajesh Rolen
Dr. Rajesh Rolen

Reputation: 14285

How to prompt user if page is idle from last 5 minuts

What is the best approach to prompt user, if he is idle on webpage from last 5 minuts. i mean how to know that use is idle on web page from last 5 minuts.

Upvotes: 2

Views: 1489

Answers (2)

zzzzBov
zzzzBov

Reputation: 179284

Just set up some event listeners with a timer to trigger a custom function/event. I'd suggest binding as many unique user-driven events as possible.

I'm going to cheat a bit and use jQuery for some demo code, this can all be done in pure javascript, but this is the sort of thing jQuery exists for:

$(window).bind( 'mousemove mouseclick keydown mousewheel ...more listeners...', idle );
function idle( e )
{
  if ( window.idleTimeout )
  {
    clearTimeout( window.idleTimeout );
  }
  window.idleTimeout = setTimeout( userIdle, 300000 );
}
function userIdle()
{
  //either do stuff here or trigger the "idle" event
  $(window).trigger('idle');
}

Upvotes: 7

makerofthings7
makerofthings7

Reputation: 61503

Use setTimeout function to call a function that logs out the user with a delay of 5 minutes.

Upvotes: 1

Related Questions