0

为会话超时实施了此操作,效果很好:

var sessionTimeoutWarning = "1";
var sessionTimeout = "2";
var timeOnPageLoad = new Date();
var sessionWarningTimer = null;
var redirectToWelcomePageTimer = null;
//For warning
var sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
//To redirect to the welcome page
var redirectToWelcomePageTimer = setTimeout('RedirectToWelcomePage()', parseInt(sessionTimeout) * 60 * 1000);

//Session Warning
function SessionWarning() {
    var minutesForExpiry = (parseInt(sessionTimeout) - parseInt(sessionTimeoutWarning));
    //var minutesForExpiry = "1";
    var message = "Your session will expire in another " + minutesForExpiry + " mins. Do you want to extend the session?";

    //Confirm the user if he wants to extend the session
    answer = confirm(message);

    //if yes, extend the session.
    if (answer) {

        //Clear the RedirectToWelcomePage method
        if (redirectToWelcomePageTimer != null) {
            clearTimeout(redirectToWelcomePageTimer);
        }

        var currentTime = new Date();
        var timeForExpiry = timeOnPageLoad.setMinutes(timeOnPageLoad.getMinutes() + parseInt(sessionTimeout));
        if (Date.parse(currentTime) > timeForExpiry) {
              alert("Session expired. You will be redirected to welcome page");
            window.location = "../login.aspx";
        }
        else {
            timeOnPageLoad = new Date();
            sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
            redirectToWelcomePageTimer = setTimeout('RedirectToLoginPage()', parseInt(sessionTimeout) * 60 * 1000);
        }
    }
    else {
        timeOnPageLoad = new Date();
        sessionWarningTimer = setTimeout('SessionWarning()', parseInt(sessionTimeoutWarning) * 60 * 1000);
        redirectToWelcomePageTimer = setTimeout('RedirectToLoginPage()', parseInt(sessionTimeout) * 1);

    }

}

//Session timeout
function RedirectToLoginPage() {
    window.location = "../login.aspx";
}

查询:当确认消息出现时,我们如何跟踪/启用如果用户在 5 分钟内没有点击该确认消息,那么我想自动关闭它并显示会话已过期的新弹出窗口。

请指教

4

1 回答 1

0

打开警报框后,您将无法控制它。您最多可以做的是在显示警告框 5 分钟后刷新页面。因此,您可以在显示警报框后编写 setTimeout,然后重定向一个页面,您可以在其中显示会话已过期的弹出窗口。

于 2012-09-03T09:30:20.770 回答