我正在尝试使用正文onmousemove="resetTimers()"
来启动javascript函数,这在Chrome和Firefox中很有效,但在Internet Explorer中效果不佳。
我向控制台写了一条日志消息,所以我知道事件何时被触发,并且基本上在IE中,如果我的鼠标在IE窗口内,即使它没有被移动,它看起来像onmousemove事件每5秒触发一次一点都不。
有人想知道为什么会这样吗?或者我如何纠正它?
我的javascript代码如下,基本上它是一个活动计时器,用于触发body onload事件上的startTimers()
函数,以及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>
答案 0 :(得分:0)
知道了,我决定废弃onmousemove事件,转而使用onscroll和onclick事件。两者仍然提供我需要的东西,我不必担心iframe刷新或ajax调用导致事件在我不希望它们时触发。感谢大家的帮助!