首页 > Web开发 > 详细

JS监听页面----无鼠标键盘动作,自动跳页

时间:2018-05-22 14:06:35      阅读:289      评论:0      收藏:0      [点我收藏+]
function ScreenSaver(settings){     

        this.settings = settings;     
        
        this.nTimeout = this.settings.timeout;     
                     
        document.body.screenSaver = this;     
        // link in to body events     
        document.body.onmousemove = ScreenSaver.prototype.onevent;     
        document.body.onmousedown = ScreenSaver.prototype.onevent;     
        document.body.onkeydown = ScreenSaver.prototype.onevent;     
        document.body.onkeypress = ScreenSaver.prototype.onevent;     
             
        var pThis = this;     
        var f = function(){pThis.timeout();}     
        this.timerID = window.setTimeout(f, this.nTimeout);     
    }     
    ScreenSaver.prototype.timeout = function(){     
        if ( !this.saver ){
            window.location = ‘www.baidu.com‘;   
        }     
    }     
    ScreenSaver.prototype.signal = function(){     
        if ( this.saver ){     
            this.saver.stop();     
        }     
             
        window.clearTimeout(this.timerID);     
             
        var pThis = this;     
        var f = function(){pThis.timeout();}     
        this.timerID = window.setTimeout(f, this.nTimeout);     
    }     
        
    ScreenSaver.prototype.onevent = function(e){     
        this.screenSaver.signal();     
    }     
        
        
    var saver;     
    function initScreenSaver(){     
        //blort;     
        saver = new ScreenSaver({timeout:5000});   //无动作时间  
    }     
    window.onload = function(){     
      initScreenSaver();     
    }     
    

 

JS监听页面----无鼠标键盘动作,自动跳页

原文:https://www.cnblogs.com/linyijia/p/9071294.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!