0

Possible Duplicate:
Detecting idle time in JavaScript elegantly

In a web application that I'm developing, on every page of the application, when nothing happens for a set amount of time, the page should automatically change. I think setting window.location will do for the latter part.

However, when it comes to detecting that nothing has happened, I'm a bit stuck. I'd think that binding all keyboard and mouse events to a single handler could do it, but I'm wondering if there is a better way. Has anyone done this before?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
MarioDS
  • 12,895
  • 15
  • 65
  • 121
  • @Bartek my bad, I should have searched better. – MarioDS Dec 21 '12 at 17:12
  • Another related question: http://stackoverflow.com/questions/1009260/how-can-i-detect-with-javascript-jquery-if-the-user-is-currently-active-on-the-p – mjk Dec 21 '12 at 17:14

2 Answers2

0

Detecting idle time in JavaScript elegantly seems to miss the blur and focus events on the window. The basic approach is as you suggested but I'd take a close look at which events exactly you're binding on.

Community
  • 1
  • 1
Halcyon
  • 57,230
  • 10
  • 89
  • 128
  • Thanks for you noticing this, but those events are irrelant in my case as the application will never lose focus. Of course, you couldn't know that. – MarioDS Dec 21 '12 at 17:25
0

Aren't running your site on a web server? A web server, such as Tomcat, can check if a session timed out.

In tomcat's web.xml you would add or change a setting:

<session-config>
    <session-timeout>60</session-timeout>
 </session-config>

In case of a session timeout, you could redirect to another page.

Here is an example:

https://stackoverflow.com/a/1027592/1916258

Community
  • 1
  • 1
asgoth
  • 35,552
  • 12
  • 89
  • 98
  • The project is written in Java (Servlets and JSP) and deployed on Tomcat. So suppose we have this session timeout, how can you detect it and take action accordingly? I must warn you though, that I will not prefer this solution because it's server dependant. – MarioDS Dec 21 '12 at 17:34
  • I've added an example (link to another question) in my answer. – asgoth Dec 21 '12 at 17:41