开发者

Javascript idle visitor checking

Is开发者_运维知识库 there a Javascript library (preferably a jQuery plugin) or simple mechanism to check if a visitor is idle? For example, if the visitor to a webpage has been there more than 5 minutes only moving their mouse but not clicking any buttons or pressing any keys, then call a particular Javascript function.

It seems like I could just call setTimeout() for my desired idle time and then call clearTimeout() upon any mouse click or keyboard press by having something like $('body').click(clearTimeout(.... But I'm sure there are issues I don't want to have to figure out. The one thing I definitely don't want to have happen is for my site to think someone's been idle and they haven't really been. The other way around is ok.


Yes, very possible and there are a couple sites that use this (like banks and Mint) with great success. Take a look at these two blog posts:

http://www.erichynds.com/jquery/creating-a-mint-com-style-idle-logout-timer-using-jquery/ http://www.erichynds.com/jquery/a-new-and-improved-jquery-idle-timeout-plugin/

I have used this approach in the past with Admin pages within websites to a fair amount of success, especially after adding the modal dialog box informing users that the session was about to expire. This helps the user to feel like the web application/site is working with them to help.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜