2012-09-10 45 views
2

確認啓動前功能打開時是否有任何停止間隔的方法?確認前執行

function check(){ 
    clearInterval(interval_id); 
    if(confirm('Stream time is running out. Do you want to continue?')) 
     // 
} 

回答

1

你可以鉤住自己的代碼進入確認,如果這是有些你想要什麼:

window.proxiedConfirm = window.confirm; 
window.confirm = function() { 
    // custom interval code here 
    return window.proxiedConfirm.apply(this, arguments); 
}; 

你當然可以聽的反應以及手動:

window.proxiedConfirm = window.confirm; 
window.confirm = function() { 

    // custom interval code here 

    var result = window.proxiedConfirm.apply(this, arguments); 

    if(result) { 
     // start interval again? 
    } 

    return result; 
}; 
+0

沒有,我只需在確認之前停止間隔即可。 –

+0

@AndreshPodzimovsky:我不確定我是否遵循你的問題,然後。你想做什麼,你還沒有在你發佈的代碼中做什麼? –

+0

問題是,現在你的代碼間隔一般不會停止。 –