web页面长时间未操作自动退出登录

var lastTime = new Date().getTime();
        var currentTime = new Date().getTime();
        var timeOut = 10 * 60 * 1000; //设置超时时间: 10分

        $(function(){
            /* 鼠标移动事件 */
            $(document).mouseover(function(){
                lastTime = new Date().getTime(); //更新操作时间

            });
        });

        function testTime(){
            currentTime = new Date().getTime(); //更新当前时间
            if(currentTime - lastTime > timeOut){ //判断是否超时
                console.log("超时");
            }
        }

        /* 定时器  间隔1秒检测是否长时间未操作页面  */
        window.setInterval(testTime, 1000);

---------------------

本文来自 csdn_wwp 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/wwp231/article/details/52127107?utm_source=copy 

使用 mouseover 事件来监测是否有用户操作页面,写一个定时器间隔特定时间检测是否长时间未操作页面,如果是,退出; 

猜你喜欢

转载自blog.csdn.net/gaoxiang24/article/details/82899467