首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >body onmousemove事件Internet Explorer 8、9、10

body onmousemove事件Internet Explorer 8、9、10
EN

Stack Overflow用户
提问于 2013-06-13 23:33:39
回答 1查看 395关注 0票数 0

我正试着用body onmousemove="resetTimers()"来启动一个javascript函数,它在Chrome和火狐浏览器中运行得很好,但在in浏览器中却不能很好地工作。

我向控制台写入了一条日志消息,这样我就可以知道事件何时触发,而且基本上在IE中,如果我的鼠标在IE窗口内,那么onmousemove事件就会每隔5秒触发一次,即使它根本没有被移动。

有人知道为什么会发生这种事吗?或者我怎样才能纠正它?

我的javascript代码如下,基本上它是一个活动计时器,在body onload事件上触发startTimers()函数,在body onmousemove事件上触发resetTimers()函数。

任何帮助都将不胜感激!再说一次,Chrome和Firefox运行得很好,IE就不行了,这是个数字。

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-07 22:43:22

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17091161

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档