2016-12-14 9 views
0

我有confirm()函數的問題。它似乎忽略了setTimeout()函數並立即調用它自己。如何使JS函數不能自調用?

我希望函數在調用之前等待600秒完成。

function stillThere() { 
 
    if(confirm("Your session has expired. Are you still here?")){ 
 
\t  //Continue 
 
    } else{ 
 
    \t window.location.href = "../logout.php"; 
 
    } 
 
} 
 

 
setTimeout(stillThere, 600);

+0

後'setTimeout' – Rayon

+3

要設置600毫秒,而不是600它調用第二個 –

回答

2

setTimeout超時參數的單位是毫秒

function stillThere(){ 
 
    if(confirm("Your session has expired. Are you still here?")){ 
 
     //Continue 
 
    }else{ 
 
    \t window.location.href = "../logout.php"; 
 
    } 
 
} 
 

 
// 1 second = 1000 ms 
 
// 600 seconds = 600000 ms 
 
setTimeout(stillThere, 600000);

+0

哈哈!我無法相信自己!謝謝你解決了! –