How to identify user idle state by minutes using javascript / JQuery?

Descrption:

i used with 20 minute of interval if user is in idle state from last 20 minute then it will call the timerIncrement() and then will check for 20 minutes if yes or not.

Why i need this?

i need to do this because of when i am creating an app using angular-4 then  i need to logout any user if he/she is in idle state from last 20 minutes.

$(document).ready(function () {
    var idleTime = 0;
    //Increment the idle time counter every minute.
    var idleInterval = setInterval(timerIncrement, 60000); // 1 minute

    //Zero the idle timer on mouse movement.
    $(this).mousemove(function (e) {
        idleTime = 0;
    });
    $(this).keypress(function (e) {
        idleTime = 0;
    });


function timerIncrement() {
    idleTime++;
    if (idleTime > 20) { // 20 minutes
         localStorage.removeItem('currentUser');

    }
}
});
Advertisements

About Hiren Kubavat

PHP Developer
This entry was posted in angular-4, Javascript, jQuery and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s