我想创建一个脚本,它可以自动检查用户是否在屏幕页面上执行某些活动。 如果在1分钟内没有收到任何活动,那么我想提醒他要求空闲的原因。 我认为这可以在jquery / javascript和php中完成。 有人可以给我任何东西,这样我就可以实现梦想。
如果他没有点击任何项目,那么在总共1分钟后自动注销。
答案 0 :(得分:3)
setTimeout
设置一个侦听器函数,以检查过去的时间和第一个变量。如果是,则取消收听,否则如果过去的时间是<一分钟继续听,如果时间过去> 1分钟提醒用户并采取行动有关此算法的q& d示例,请参阅this jsfiddle
祝你好运!答案 1 :(得分:2)
这个插件可以解决这个问题
<!-- 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 ,您可以将请求发送到服务器以关闭会话
答案 2 :(得分:2)
您必须在body标签上添加不同的事件处理程序,以确定用户是否处于非活动状态。我认为onmousemove,oncllick和onkeypress事件就足够了。
这样做。