为会话超时实施了此操作,效果很好:
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 分钟内没有点击该确认消息,那么我想自动关闭它并显示会话已过期的新弹出窗口。
请指教