当前位置: 代码迷 >> Web前端 >> setTimeout跟clearTimeout的session用法
  详细解决方案

setTimeout跟clearTimeout的session用法

热度:401   发布时间:2012-10-11 10:16:10.0
setTimeout和clearTimeout的session用法
var sessionTime = 1200;//empire time
var delay = 1000;
var timeId = null;
var timerRunning = false;
var windowStatusMsg;
var isStatusAvail = true; 
initTimer();
function initTimer(){
	secs = sessionTime;
	stopClock();
	startTimer();
}
function stopClock(){
	if(timerRunning){
		clearTimeout(timeId);
	}
	timerRunning = false;
}
function startTimer(){
	if(secs == 0){
		stopClock();
		
		windowStatusMsg = "The session is empired";
	} else {
		secs = secs - 1;
		var min = secs/60;
		var res = Math.floor(min);
		var sec = secs%60;
		timerRunning = true;
		timerId = self.setTimeout("startTimer()",delay);
		if(secs>=1 && secs<=59){
			if(secs==10){
				alert("Session will be expired after 10 seconds!");
			}
			windowStatusMsg = "Your session will expire within "+sec+ " second(s)";
		}else{
			windowStatusMsg = "Your session will expire within "+res+" minute(s) and " +sec+ " second(s)";
		}
	}
	if(isStatusAvail){
		window.status = windowStatusMsg;
	}
}

?

  相关解决方案