gpt4 book ai didi

javascript - 如何让JS函数不被自调用?

转载 作者:行者123 更新时间:2023-12-02 13:49:14 24 4
gpt4 key购买 nike

我对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);

最佳答案

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);

关于javascript - 如何让JS函数不被自调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41134831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com