i编写方法以重置mouse click
,KEYUP和keypress
上的超时,但是我只是意识到它不会检查输入字段,因此当我在字段中积极键入字段时,它将超时。这是我的代码:
var idleInterval = setInterval(timerIncrement, 10000);
var idleTime = 0;
$(document).ready(function () {
//Increment the idle time counter every minute.
//Zero the idle timer on mouse movement.
$(this).mousemove(function (e) {
idleTime = 0;
});
$(this).keypress(function (e) {
idleTime = 0;
});
$(this).keyup(function (e) {
idleTime = 0;
});
});
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime > 4) {
window.location.replace('/timeout.aspx');
}
}
您应该拥有document.ready()
函数中的所有代码。
$(document).ready(function() {
var idleInterval = setInterval(timerIncrement, 10000);
var idleTime = 0;
$(document).on('keyup', function() {
console.log('Keyup Detected');
idleTime = 0;
});
function timerIncrement() {
idleTime++;
if (idleTime > 4)
window.location.replace('/timeout.aspx');
}
});
您可以使用此jQuery函数来检测页面上的所有密钥:
$(document).on("keypress", function (e) {
idleTime = 0;
});
,您的代码应该看起来像:
var idleInterval = setInterval(timerIncrement, 10000);
var idleTime = 0;
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime > 4) {
window.location.replace('/timeout.aspx');
}
}
$(document).ready(function () {
$(this).mousemove(function (e) {
idleTime = 0;
});
$(document).on("keypress", function (e) {
idleTime = 0;
});
});