Jquery 如果用户处于活动状态,则禁用所有窗口的扩展会话弹出窗口

Jquery 如果用户处于活动状态,则禁用所有窗口的扩展会话弹出窗口,jquery,Jquery,在My screens.js中,我检查用户是否空闲。如果空闲,我将显示seeion extend弹出窗口。但问题是,在screen.js上面使用的是引用所有页面。(这是common.js) 以上一项用于检查用户是否空闲 之后,我设置了检查用户空闲状态和会话时间的间隔。若用户空闲且会话时间等于会话到期,则会显示会话扩展弹出窗口 让我们假设一个情景。 若用户在X页上打开X页和Y页,则用户执行某些活动意味着用户处于非空闲状态。但在Y页面上,用户不会执行任何活动,这意味着用户处于空闲状态。由于Y页面会话

在My screens.js中,我检查用户是否空闲。如果空闲,我将显示seeion extend弹出窗口。但问题是,在screen.js上面使用的是引用所有页面。(这是common.js)

以上一项用于检查用户是否空闲

之后,我设置了检查用户空闲状态和会话时间的间隔。若用户空闲且会话时间等于会话到期,则会显示会话扩展弹出窗口

让我们假设一个情景。 若用户在X页上打开X页和Y页,则用户执行某些活动意味着用户处于非空闲状态。但在Y页面上,用户不会执行任何活动,这意味着用户处于空闲状态。由于Y页面会话,我不希望出现扩展弹出窗口,因为用户正在X页面上执行活动

  sessionCheckInterval = setInterval(showSessionExpireModal, 5000);//interval for session pop up
函数代码在这里

function showSessionExpireModal() {
    currentSystemTime = new Date(moment(new Date()).format('MM/DD/YYYY HH:mm:ss'));
    if (!idleState) return;
    console.log("idleState:" + idleState + " currentSystemTime: " + currentSystemTime + " sessionExpiredTime: " + sessionExpiredTime);
    if ((idleState) && moment(currentSystemTime).format('MM/DD/YYYY HH:mm:ss') == moment(sessionExpiredTime).format('MM/DD/YYYY HH:mm:ss')) {
            $('#SessionExpireModal').foundation('reveal', 'open');
            currentSystemTime = new Date(moment(new Date()).format('MM/DD/YYYY HH:mm:ss'));
            sessionExpiredTime = new Date(moment(moment(new Date(currentSystemTime)).add(1, 'm').toDate()).format('MM/DD/YYYY HH:mm:ss'));
            countDownInterval = setInterval(function () {
                counter = counter - duration;
                if (counter == 0) {
                    $('#SessionExpireModal').foundation('reveal', 'close');
                    clearTimeout(countDownInterval);
                    counter = 60;
                    clearTimeout(sessionCheckInterval);
                    window.location.href =  '/User/SessionExpired';
                }
                $('#countDownTimer').text(counter);
            }, 1000);
    }
}

如果用户在一个屏幕上执行活动与在其他屏幕上执行活动相比,是否可以防止模式弹出。任何建议

在我看来,你不能用JavaScript解决这个问题

您应该通过服务器会话处理来控制用户活动。例如,通过AJAX向服务器发送任何动作的“我是现场信号”。将最后一个活动时间保存在会话变量中,并在一段时间间隔内通过AJAX分别询问最后一个活动时间现在和最后一个活动之间的时间差。根据不同,您可以显示一个弹出窗口(在每个打开的页面上)

使用依赖于会话的WebSocket的解决方案会稍微复杂一点

function showSessionExpireModal() {
    currentSystemTime = new Date(moment(new Date()).format('MM/DD/YYYY HH:mm:ss'));
    if (!idleState) return;
    console.log("idleState:" + idleState + " currentSystemTime: " + currentSystemTime + " sessionExpiredTime: " + sessionExpiredTime);
    if ((idleState) && moment(currentSystemTime).format('MM/DD/YYYY HH:mm:ss') == moment(sessionExpiredTime).format('MM/DD/YYYY HH:mm:ss')) {
            $('#SessionExpireModal').foundation('reveal', 'open');
            currentSystemTime = new Date(moment(new Date()).format('MM/DD/YYYY HH:mm:ss'));
            sessionExpiredTime = new Date(moment(moment(new Date(currentSystemTime)).add(1, 'm').toDate()).format('MM/DD/YYYY HH:mm:ss'));
            countDownInterval = setInterval(function () {
                counter = counter - duration;
                if (counter == 0) {
                    $('#SessionExpireModal').foundation('reveal', 'close');
                    clearTimeout(countDownInterval);
                    counter = 60;
                    clearTimeout(sessionCheckInterval);
                    window.location.href =  '/User/SessionExpired';
                }
                $('#countDownTimer').text(counter);
            }, 1000);
    }
}