开发者

How can a web application detect the user's idle time?

I am working on a browser-based instant messaging client, and this app开发者_StackOverflowlication needs to know when the user is idle, if possible. Is there a way, in any major browser, for the application to detect the user's idle time system-wide? Failing that, are there any recommended techniques for detecting when the user was last active in the application itself, and possibly in other pages under the same domain?


If user goes to different page, we can assume he's not idle, so the problem gets reduced to 'is user active on current page?'

You can set timeout in onMouseMove event of body. When timeout fires, you know user's been inactive for some period of time. If it doesn't, and you receive a onMouseMove before timeout, you simply clear the timeout. You can also deal with onKeyPress in the same way.

This could be a little harder if user would open many tabs of your page, but I would just use localStorage for some way of communication between those tabs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜