码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2018-05-22 15:04:51      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:time   .com   new   bsp   sed   页面   无鼠标   www.   save   

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监听页面----无鼠标键盘动作,自动跳页

标签:time   .com   new   bsp   sed   页面   无鼠标   www.   save   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!