0

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>
4

1 回答 1

0

明白了,我决定放弃 onmousemove 事件,转而使用 onscroll 和 onclick 事件。两者仍然提供我需要的东西,我不必担心 iframe 刷新或 ajax 调用会导致事件在我不希望触发时触发。感谢大家的帮助!

于 2013-11-07T14:43:21.803 回答