var IDLE_TIMEOUT = 2700; //seconds 45min
var _idleSecondsCounter = 0;
document.onclick = function() {
_idleSecondsCounter = 0;
};
document.onmousemove = function() {
_idleSecondsCounter = 0;
};
document.onkeypress = function() {
_idleSecondsCounter = 0;
};
window.setInterval(CheckIdleTime, 1000);
function CheckIdleTime() {
_idleSecondsCounter++;
var oPanel = document.getElementById("SecondsUntilExpire");
if (oPanel)
oPanel.innerHTML = (IDLE_TIMEOUT - _idleSecondsCounter) + "";
if (_idleSecondsCounter >= IDLE_TIMEOUT) {
//alert("Your Session Time expired. Please Login.");
document.location.href = "logoff.php";
}
}
<div id='SecondsUntilExpire'></div>
所以從上面我得到的輸出爲2699(其以秒= 45分鐘),如果沒有事件發生的遞減(2698..2697..and所以上),如果任何事件(鼠標up..etc)發生了回2699
但我需要在幾分鐘內那:44:59,44:58 ..和等
退房這種情況下,您需要格式化https://stackoverflow.com/questions/3733227/javascript-seconds-to-minutes- and-seconds – Scuzzy
你使用什麼瀏覽器? –
我正在使用火狐 – user3209031