如果在页面上未找到活动,则自动注销
Automatic log-out if no activity found on page
我想制作一个脚本,它可以自动检查用户是否正在屏幕上执行某些活动。如果在 1 分钟内没有收到任何活动,那么我想提醒他询问空闲的原因。我认为这可以在jquery/javascript和php中完成。有人可以给我任何东西,这样我就可以实现我的梦想。
如果他没有点击任何项目,那么在总共 1 分钟后自动注销。
- 设置一个变量以指示用户活动,最初为 false
- 设置指示当前时间的变量
- 设置文档范围单击处理程序,以便在用户单击页面中的任意位置时将用户活动设置为 True
- 使用
setTimeout
设置侦听器函数以检查过去的时间和第一个变量。如果是真的,请取消收听,否则,如果过去的时间<一分钟,请继续收听,如果超过>则提醒用户并采取您的操作
有关此算法的问答示例,请参阅此jsfiddle
。祝你好运!
空闲插件
这个插件可以解决问题
<!-- dialog window markup -->
<div id="dialog" title="Your session is about to expire!">
<p>You will be logged off in <span id="dialog-countdown"></span> seconds.</p>
<p>Do you want to continue your session?</p>
</div>
// setup the dialog
$("#dialog").dialog({
autoOpen: false,
modal: true,
width: 400,
height: 200,
closeOnEscape: false,
draggable: false,
resizable: false,
buttons: {
'Yes, Keep Working': function(){
// Just close the dialog. We pass a reference to this
// button during the init of the script, so it'll automatically
// resume once clicked
$(this).dialog('close');
},
'No, Logoff': function(){
// fire whatever the configured onTimeout callback is.
$.idleTimeout.options.onTimeout.call(this);
}
}
});
// start the plugin
$.idleTimeout('#dialog', 'div.ui-dialog-buttonpane button:first', {
idleAfter: 300, // user is considered idle after 5 minutes of no movement
pollingInterval: 60, // a request to keepalive.php (below) will be sent to the server every minute
keepAliveURL: 'keepalive.php',
serverResponseEquals: 'OK', // the response from keepalive.php must equal the text "OK"
onTimeout: function(){
// redirect the user when they timeout.
window.location = "timeout.htm";
},
onIdle: function(){
// show the dialog when the user idles
$(this).dialog("open");
},
onCountdown: function(counter){
// update the counter span inside the dialog during each second of the countdown
$("#dialog-countdown").html(counter);
},
onResume: function(){
// the dialog is closed by a button in the dialog
// no need to do anything else
}
});
并使用 Ajax,您可以将请求发送到服务器以关闭会话
您必须在 body 标记上添加不同的事件处理程序,以确定用户是否处于非活动状态。我认为onmousemove,oncllick和onkeypress事件就足够了。
- 您应该启动一个计时器,当它达到特定时间时,您只需转到注销 URL
- 实现提到的事件处理程序。在它们内部重置计时器。
这样就行了。
相关文章:
- 使用Dnamics CRM 2011中的JavaScript读取子网格的所有记录,而不考虑活动页面
- 字符串在将其传递给另一个活动Android JavaScript时读取Null
- 活动选项卡's源代码-获取变量s值
- 在Angular 2中布线期间保持零部件处于活动状态
- 在ajax成功后,cluetip不适用于首次点击活动元素
- 如何使bxslider仅在移动视图中处于活动状态
- JQuery中的活动搜索栏
- 显示具有服务器端自动时间注销的同步倒计时计时器
- 悬停下拉菜单即使在鼠标移出后也保持活动状态
- 将js添加到wordpress中以突出显示css活动菜单
- Google 脚本:用于创建日历活动的脚本运行时不会出错,但不会执行任何操作
- 手动创建旋转活动指示器
- 当没有用户活动时自动注销
- Jasvascript :不活动后发出警报通知,并在 5 分钟后注销
- 如果在页面上未找到活动,则自动注销
- javascript自动注销10分钟的非活动状态
- 如果jsp页面在3分钟内处于非活动状态,我如何在3分钟后注销它
- 在一段时间不活动后注销用户
- 如何在 30 分钟后注销非活动用户
- 在处于非活动状态后注销电子表格