我有一個小時後超時會話的頁面。我需要在45分鐘後顯示彈出警報,然後在50-60分鐘內使用JavaScript或jQuery(我不知道jQuery,但它是可用的)每分鐘顯示一次。在60分鐘的時間內,我需要最終的消息通知用戶頁面將刷新。得到我的部分是如果顯示一個彈出窗口,除了最後一個窗口之外,其他人都不應該關閉。即如果顯示10分鐘彈出窗口但不關閉2分鐘,則9和8分鐘彈出窗口不應該顯示,但7分鐘應該顯示。僅在上一個彈出窗口關閉時纔會顯示多個JavaScript超時彈出窗口
到目前爲止,我想出了一個被稱爲在頁面加載的功能,但它是既醜陋和不工作:
// Alerts starting at 45 minutes into session, then from 10 - 1, and a final alert
var timerMultiplier = 10000; //used so I can change times in testing
var timeoutAlertAcknowledged = true; //a flag I've tried using to know when a box has been closed
function setTimeoutAlerts(){
if(document.getElementById("$!arsTO.getConstantValue('FIELD_NAME_ROW_COUNT')").value > 0){
var sessionWarningTime15=setInterval(function() {myTimer('warning',15, sessionWarningTime15)}, 270*timerMultiplier);
var sessionWarningTime10=setInterval(function() {myTimer('warning',10, sessionWarningTime10)}, 300*timerMultiplier);
var sessionWarningTime9=setInterval(function() {myTimer('warning',9, sessionWarningTime9)}, 306*timerMultiplier);
var sessionWarningTime8=setInterval(function() {myTimer('warning',8, sessionWarningTime8)}, 312*timerMultiplier);
var sessionWarningTime7=setInterval(function() {myTimer('warning',7, sessionWarningTime7)}, 318*timerMultiplier);
var sessionWarningTime6=setInterval(function() {myTimer('warning',6, sessionWarningTime6)}, 324*timerMultiplier);
var sessionWarningTime5=setInterval(function() {myTimer('warning',5, sessionWarningTime5)}, 330*timerMultiplier);
var sessionWarningTime4=setInterval(function() {myTimer('warning',4, sessionWarningTime4)}, 336*timerMultiplier);
var sessionWarningTime3=setInterval(function() {myTimer('warning',3, sessionWarningTime3)}, 342*timerMultiplier);
var sessionWarningTime2=setInterval(function() {myTimer('warning',2, sessionWarningTime2)}, 348*timerMultiplier);
var sessionWarningTime1=setInterval(function() {myTimer('warning',1, sessionWarningTime1)}, 354*timerMultiplier);
var sessionEndTime=setInterval(function() {myTimer('timesUp',0, sessionEndTime)}, 360*timerMultiplier);
}
}
//Create popup alerts
function myTimer(type, time, timerVariable) {
clearInterval(timerVariable); //clear current timer variable so it only occurs once
if(type == 'warning' && timeoutAlertAcknowledged == true){
timeoutAlertAcknowledged = false;
alert("WARNING: Your session will expire in "+ time +" minutes.");
}
else if(type == 'timesUp'){
alert("The session has expired. The page will now be refreshed.");
pageRefreshMethod();
}
}
1)使用的setTimeout 2.設置函數內部的下一個超時你超時3調用)不要使用警報,而是顯示並隱藏絕對位置或位置:固定div或甚至可以移動或解散的對話框 – mplungjan