如果用户当前在页面上处于活动状态,我如何使用JavaScript / jQuery进行检测? [英] How can I detect with JavaScript/jQuery if the user is currently active on the page?

查看:236
本文介绍了如果用户当前在页面上处于活动状态,我如何使用JavaScript / jQuery进行检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在当前页面上检测用户何时处于非活动状态(不是单击或键入)超过30分钟。

I am needing to detect when a user is inactive (not clicking or typing) on the current page for more than 30 minutes.

我认为这可能是最好的使用贴在body标签上的事件blubbling,然后继续重置计时器30分钟,但我不确定如何创建它。

I thinking it might be best to use event blubbling attached to the body tag and then just keep resetting a timer for 30 minutes, but I'm not exactly sure how to create this.

我有jQuery可用,虽然我不确定实际使用jQuery有多少。

I have jQuery available, although I'm not sure how much of this will actually use jQuery.

编辑:我更需要知道他们是否正在积极使用该网站,因此点击(更改字段或字段内的位置或选择复选框/无线电)或键入(在输入,textarea等)。如果他们在另一个标签或使用其他程序,那么我的假设是他们没有使用该网站,因此应该退出(出于安全原因)。

I'm more needing to know if they are actively using the site, therefore clicking (changing fields or position within a field or selecting checkboxes/radios) or typing (in an input, textarea, etc). If they are in another tab or using another program, then my assumption is they are not using the site and therefore should be logged out (for security reasons).

编辑#2:所以每个人都清楚,这根本不是用于确定用户是否已登录,经过身份验证或其他任何内容。现在,如果用户在30分钟内没有发出页面请求,服务器会将用户注销。此功能可防止有人花费> 30分钟填写表单然后提交表单以发现他们尚未注销的时间。因此,这将与服务器站点结合使用,以确定用户是否处于非活动状态(不是单击或键入)。基本上,交易是在闲置25分钟后,他们将看到一个对话框输入他们的密码。如果他们不在5分钟内,系统会自动将其注销,并且服务器的会话将被注销(下次访问页面时,与大多数网站一样)。

Edit #2: So everyone is clear, this is not at all for determining if the user is logged in, authenticated or anything. Right now the server will log the user out if they don't make a page request within 30 minutes. This functionality to prevent the times when someone spends >30 minutes filling in a form and then submitting the form only to find out that they haven't been logged out. Therefore, this will be used in combination with the server site to determine if the user is inactive (not clicking or typing). Basically, the deal is that after 25 minutes of idle, they will be presented with a dialog to enter their password. If they don't within 5 minutes, the system automatically logs them out as well as the server's session is logged out (next time a page is accessed, as with most sites).

Javascript仅用作对用户的警告。如果JavaScript被禁用,那么他们将不会收到警告(并且大部分网站都无法正常工作),他们将在下次请求新页面时注销。

The Javascript is only used as a warning to user. If JavaScript is disabled, then they won't get the warning and (along with most of the site not working) they will be logged out next time they request a new page.

推荐答案

您可以观看鼠标移动,但这是关于你在没有收听点击事件的情况下仍然存在的用户的最佳信息。但javascript无法判断它是活动标签还是浏览器甚至是打开的。 (好吧,你可以得到浏览器的宽度和高度,并告诉你它是否被最小化)

You can watch mouse movement, but that's about the best you're going to get for indication of a user still being there without listening to the click event. But there is no way for javascript to tell if it is the active tab or if the browser is even open. (well, you could get the width and height of the browser and that'd tell you if it was minimized)

这篇关于如果用户当前在页面上处于活动状态,我如何使用JavaScript / jQuery进行检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆