zoukankan      html  css  js  c++  java
  • 网站10分钟不操作会话退出

    方式一

        <script type="text/javascript">
            var maxTime = 10; // seconds
            var time = maxTime;
            $('body').on('keydown mousemove mousedown', function (e) {
                time = maxTime; // reset
            });
            var intervalId = setInterval(function () {
                time--;
                if (time <= 0) {
                    ShowInvalidLoginMessage();
                    clearInterval(intervalId);
                }
            }, 1000)
            function ShowInvalidLoginMessage() {
                // 清除cookie
                // 提示用户
                // 该干嘛干嘛
                alert('那么长时间没动弹,退出喽!');
                $.ajax({
                    url: "RegisterCheck.csx?tag=logout",
                    dataType: "text",
                    success: function (response, p) {
                        window.location.href = "Login.html";
                    }
                })
            }
        </script>

     方式二

    function ReLogin() {
        window.location.href = "Login2.html";
    };
    
    var maxTime = 900; // seconds
    var time = maxTime;
    $(function () {
        /* 鼠标移动事件 */
        $(document).mouseover(function () {
            time = maxTime;
        });
        $(document).mousedown(function () {
            time = maxTime;
        });
    });
    
    var intervalId = setInterval(function () {
        time--;
        console.log("倒计时:" + time);
        if (time <= 0) {
            ShowInvalidLoginMessage();
            clearInterval(intervalId);
        }
    }, 1000)
    function ShowInvalidLoginMessage() {
        var title = '提示', content = '那么长时间没动弹,退出喽!';
        Ext.MessageBox.alert(title, content, function (r) {
            Ext.Ajax.request({
                url: "RegisterCheck.csx",
                params: {
                    tag: "logout"
                },
                success: function () {
                    ReLogin();
                }
            });
        });
    }
  • 相关阅读:
    SQL server查询笔记
    thinkphp ajax无刷新上传头像
    JSTL
    EL表达式
    jBox 弹框内容交互
    网页可读不可写
    readonly与disable的区别
    vuex 的使用
    页面向上滚动
    按照数组中的对象属性进行排序
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/12409857.html
Copyright © 2011-2022 走看看