我们的网站有 ifame 链接到不同的内容网站,这些网站用于进行在线考试 内容页面中的一些考试持续了 3 个多小时 还有考试 guard 可以防止用户在考试时做其他事情
问题是,一旦用户在 3 小时以上完成考试并来到父站点(我们的站点) 它在父页面中存在 session 超时问题,(父站点 session 超时设置为 180 分钟)
作为解决方案,我们已经实现了 JQuery
var to;
$(document).ready(function () {
to = setTimeout("TimeOut()", 10000);
});
function TimeOut() {
$.ajax({ type: "POST",
url: "KeepAliveDummy.aspx", success: function () {
to = setTimeout("TimeOut()", 10000);
}
});
};
现在的问题是,如果一个用户打开父网站然后离开,它将意外地保持 session ,
对于捕获空闲时间有什么建议吗?
最佳答案
我们可以使用“mousemove”事件来查看用户是否处于事件状态。
我已经使用下面的代码来测试用户空闲时间是否达到了最大空闲时间。
function checkIdleTimeOut() {
userIdleTime++;
if( userIdleTime >= maxIdleTime ) {
alert("Reached max User Idle Time");
clearInterval(intvl);
}
$("#output").html( "userIdleTime: " + userIdleTime );
}
我提供了一个示例演示,其中最大空闲时间设置为 5 秒。
演示在 JSFiddle Demo
关于javascript - 使用javascript捕获用户空闲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21595712/