92014Sep

Check User Active Status Using Idle Timer

There are most of the time when there is requirement for setting session timeout when user is idle for sometime. Like there are ajax requests going on for users who are logged in e.g notification call, new messages call. But the user is idle or leaves the browser open for long time so in that case you might be need to stop unwanted ajax calls to avoid server overhead.

So There is a jquery script Idle Timer you can use to check user active status. The code is :-

<script type="text/javascript">

jQuery(document).ready(function(e) {
		tt_exp     = 500000; //set the time in microsecond
		
		//This event will fire when user idle time exceeded.
        jQuery(document).bind("idle.idleTimer", function(){
			// can send ajax calls
			// can send calls for destroying user session.
			// can refresh the window.
			// can make an alert.
        });
		
		//This event will fire when user comes back to your website.
        jQuery(document).bind("active.idleTimer", function(){
			// code when user become active.
		});
		
		// calling idle timer plugin.
        jQuery.idleTimer(tt_exp);
        

});

</script>

Make sure you have included Idle Timer Script

The above script will check user mouse movement on your web page and fire the events for user statuses.