js根据鼠标和键盘判断页面是否长时间未进行操作

<script>
    var count = 0;
    var outTime = 1;//分钟
    window.setInterval(go, 1000);

    function go() {
        count++;
        if (count == outTime * 60) {
            // alert("设置时长N分钟无鼠标键盘操作,自动跳转下一个页面");
            window.location.href = "tianjin.html?backurl=" + window.location.href;
        }
    }

    var x;
    var y;
    //监听鼠标
    document.onmousemove = function (event) {
        var x1 = event.clientX;
        var y1 = event.clientY;
        if (x != x1 || y != y1) {
            count = 0;
        }
        x = x1;
        y = y1;
    };
    //监听键盘
    document.onkeydown = function () {
        count = 0;
    };
</script>

  

posted @ 2018-07-20 13:47  webfby  阅读(1512)  评论(1编辑  收藏  举报