我遇到了confirm()函数的问题。它似乎忽略了setTimeout()
函数并立即调用它。
我希望函数在调用之前等到600秒完成。
function stillThere () {
if(confirm("Your session has expired. Are you still here?")){
//Continue
} else{
window.location.href = "../logout.php";
}
}
setTimeout(stillThere, 600);

答案 0 :(得分:2)
setTimeout
的超时参数是以毫秒为单位的数字
function stillThere (){
if(confirm("Your session has expired. Are you still here?")){
//Continue
}else{
window.location.href = "../logout.php";
}
}
// 1 second = 1000 ms
// 600 seconds = 600000 ms
setTimeout(stillThere, 600000);