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>
相關文章
相關標籤/搜索