I'm trying to fire off a javascript function using body onmousemove="resetTimers()"
, which works teriffic in Chrome and Firefox, but does not work so well in Internet Explorer.
I wrote to the console a log message so i knew when the event was firing, and basically in IE it looks like the onmousemove event fires every 5 seconds if my mouse is within the IE window, even if it is not being moved at all.
Anyone have any thoughts as to why this is happening? Or how I can correct it?
My javascript code is below, and basically it's an activity timer that fires the startTimers()
function on the body onload event, and the resetTimers()
function on the body onmousemove event.
Any help would be greatly appreciated! Again Chrome and Firefox work great, IE does not, which figures.
<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>