Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session Timeout in plain jQuery

Tags:

jquery

How can I write sessionTimeOut functionality in plain jQuery without using any pluging? I want to use my own alert ui.To figure out any UI activity I can write but not sure how to combine it in a timeout functionality.

$('*').on('click', function () {
    console.log('click', this);

});

$('*').on('change', function() {
    console.log('change', this);
});
like image 729
Himanshu Yadav Avatar asked Jul 19 '13 12:07

Himanshu Yadav


People also ask

What is sessiontimeout in jQuery?

More in this category... sessionTimeout is a useful jQuery plugin that popup s a timeout dialog with 'Log out' and 'keep Alive' options after a certain idle time. If 'Log Out' is clicked, the page is redirected to a specified URL.

How to show session expiration time out popup using jQuery?

Session Expiration Time out Popup using jquery 1 Introduction 2 Background. Session timeout is very much important in every project. There are so many articles already written for session timeout. 3 Using the code. To show session timeout popup we need two popups, one for showing session expire warning like “Your session will expire in -- seconds.

How to set session time and idle time in JavaScript?

We need to declare some global variables; these are used to calculate the user's idle time and session time. We need to create a JavaScript function that initializes the session time when the page loads. Here we use the sess_lastActivity variable to store the time the page is loaded and after that we set the session interval.

What is setTimeout function in jQuery?

This is a basic JavaScript function and can be used in jQuery without any extra parameters. The basic syntax or the jQuery setTimeOut function looks like this: The Complete jQuery Course: From Beginner To Advanced!


Video Answer


1 Answers

You could on all modern browsers capture mousemove event:

(function () {
    var timeoutSession;
    document.addEventListener('mousemove', function (e) {
        clearTimeout(timeoutSession);
        timeoutSession = setTimeout(function () {
            alert('Make SESSION expire');
            //call a script here to server...
        }, 30000); //30s
    }, true);
})();
like image 159
A. Wolff Avatar answered Oct 13 '22 19:10

A. Wolff