Session timeout in Javascript Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Session timeout in Javascript without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am working on a Javascripyt/html mobile app and I want to implement the session timeout feature. The easiest way is to use the setTimeout function but I want to check if any click, change event was performed before I make the decision. The logic needs to be:

checkForSessionTimeout() {
      if(delta(last logged event time) <  session timeout time) {
              // do not timeout
              // reset the delta to 0
      } else {
              //timeout and take to login page
      }
}

I am able to get the function but not sure how do I log all click and change events on the browser.

Please help!

Answer

Are you using jQuery? This example uses jQuery but you should be able to adapt it to whatever you are using: Listen for events on all DOM nodes. With jQuery, $('*').on('click', function() ...). This will let you capture events even when a more close event binding has used stopPropagation.

It should work the same for change…

An example (open console): http://jsfiddle.net/u6eDj/2/

We are here to answer your question about Session timeout in Javascript - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji