【发布时间】:2018-06-21 17:41:31
【问题描述】:
我创建了一个选项卡 A、B、C。每个选项卡都有一个 html 页面。如果我单击第一个选项卡,我已经为自动注销设置了超时功能(javascript)。如果我单击第二个选项卡,则会运行相同的超时功能。但我想停止/重置第一个选项卡计时器。
function timeout(){
var IDLE_TIMEOUT = 60; //seconds
var _idleSecondsTimer = null;
var _idleSecondsCounter = 0;
document.onclick = function() {
_idleSecondsCounter = 0;
};
document.onmousemove = function() {
_idleSecondsCounter = 0;
};
document.onkeypress = function() {
_idleSecondsCounter = 0;
};
_idleSecondsTimer = window.setInterval(CheckIdleTime, 1000);
function CheckIdleTime() {
_idleSecondsCounter++;
if (_idleSecondsCounter >= IDLE_TIMEOUT) {
window.clearInterval(_idleSecondsTimer);
alert("Time expired!");
document.location.href = "logout.php";
}
}
}
function opentab1(){
document.getElementById("tab1").innerHTML='<object type="text/html" data="tab1.php" ></object>';
}
function opentab2(){
document.getElementById("tab2").innerHTML='<object type="text/html" data="tab2.php" ></object>';
}
function opentab3(){
document.getElementById("tab3").innerHTML='<object type="text/html" data="tab3.php" ></object>';
}
function opentab4(){
document.getElementById("tab4").innerHTML='<object type="text/html" data="tab4.php" ></object>';
}
<body>
<div class="tab1" onload="timeout()" onclick="opentab1()">
</div>
<div class="tab2" onload="timeout()" onclick="opentab2()">
</div>
<div class="tab3" onload="timeout()" onclick="opentab3()">
</div>
<div class="tab4" onload="timeout()" onclick="opentab4()">
</div>
// loading an php file using on click function
<div class="container" id="tab1"></div>
<div class="container" id="tab2"></div>
<div class="container" id="tab3"></div>
<div class="container" id="tab4"></div>
</body>
提前致谢。请指导。
【问题讨论】:
-
试着把
var _idleSecondsTimer = null放在timeout()函数的外面
标签: javascript php html css