我正试着用body onmousemove="resetTimers()"来启动一个javascript函数,它在Chrome和火狐浏览器中运行得很好,但在in浏览器中却不能很好地工作。
我向控制台写入了一条日志消息,这样我就可以知道事件何时触发,而且基本上在IE中,如果我的鼠标在IE窗口内,那么onmousemove事件就会每隔5秒触发一次,即使它根本没有被移动。
有人知道为什么会发生这种事吗?或者我怎样才能纠正它?
我的javascript代码如下,基本上它是一个活动计时器,在body onload事件上触发startTimers()函数,在body onmousemove事件上触发resetTimers()函数。
任何帮助都将不胜感激!再说一次,Chrome和Firefox运行得很好,IE就不行了,这是个数字。
<script type="text/javascript">
// Set timeout variables
var timoutWarning = 10000;
var dialogTimeout = 30; // Countdown on idle timeout in seconds
var logoutUrl = '/logout.php'; // URL to logout page
var warningTimer;
var dialogTimer;
var $popupDialog;
// Start timers
function startTimers() {
warningTimer = setTimeout("idleWarning()", timoutWarning);
}
// Reset timers
function resetTimers() {
console.log('resetTimers was called');
clearTimeout(warningTimer);
clearTimeout(dialogTimer);
startTimers();
if(typeof $popupDialog !== 'undefined'){
$popupDialog.dialog('close');
}
dialogTimeout=30;
}
// Show idle timeout warning dialog.
function idleWarning() {
clearTimeout(warningTimer);
$popupDialog = $('<div></div>')
.html('<p>Are you still there? If no activity is detected within the next 30 seconds you will be automatically logged out!</p>')
.dialog({
autoOpen: false,
modal: true,
height: 140,
width: 350,
title: 'Session Timeout'});
$popupDialog.dialog('open');
countdownTimer();
}
// Logout the user.
function idleTimeout() {
//document.location = logoutUrl;
}
//Countdown 30 second timer
function countdownTimer() {
dialogTimer=setTimeout("countdownTimer()",1000);
if(dialogTimeout>0) {
if(dialogTimeout>1){
$popupDialog.html('<p>Are you still there? If no activity is detected within the next '+dialogTimeout+' seconds you will be automatically logged out!</p>');
} else {
$popupDialog.html('<p>Are you still there? If no activity is detected within the next '+dialogTimeout+' second you will be automatically logged out!</p>');
}
} else {
if(typeof $popupDialog !== 'undefined'){
$popupDialog.dialog('close');
}
idleTimeout();
}
dialogTimeout-=1;
}
</script>发布于 2013-11-07 22:43:22
明白了,我决定放弃onmousemove事件,转而使用onscroll和onclick事件。它们仍然提供了我需要的东西,而且我不必担心iframe刷新或ajax调用导致事件在我不希望它们触发时触发。感谢大家的帮助!
https://stackoverflow.com/questions/17091161
复制相似问题