如何使JS函数不能自我调用?

时间:2016-12-14 04:25:10

标签: javascript jquery

我遇到了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);




1 个答案:

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