2013-05-22 193 views
2

如何在navigator.notification.confirm打開時檢測返回按鈕事件?後退按鈕只是關閉彈出窗口,但事件document.addEventListener('backbutton',onBackKeyDown,false);不會升起。如何檢測後退按鈕事件?

+0

我添加了Phonegap標記,因爲這主要是Phonegap問題。此外,這不是一個批評,但不要指望沒有代碼示例的解決方案,即使它被分類。 – Gajotres

回答

0

在您傳遞到navigator.notification.confirm API的success回調中,您可以獲取單擊了哪個按鈕的buttonIndex。它沒有記錄,但是如果buttonIndex = 0,那麼用戶或者在對話框之外點擊關閉它或者點擊Back按鈕。

因此,例如:

function makeConfirm(){ 
     navigator.notification.confirm(
      'You are the winner!', // message 
      onConfirm,    // callback to invoke with index of button pressed 
      'Game Over',   // title 
      'Restart,Exit'   // buttonLabels 
     );   
    } 

    function onConfirm(buttonIndex){ 
     console.log("confirmation! Button clicked was:" + buttonIndex); 
     if(buttonIndex===0){ 
      // they either hit back button or tapped the area outside of the dialog 
     } 
    } 

我不知道是否有一種方法,以確定他們是否點擊了實際的硬件後退按鈕或剛剛點擊關閉對話框。你也許可以在頁面主體上註冊點擊事件,看看是否被觸發,如果有,並且他們在對話框外單擊。如果buttonIndex===0但它沒有被解僱,他們點擊硬件後退按鈕。

我也讀過關於使用JQM來檢測後退按鈕是否被按下的StackOverflow的其他問題;也許你可以用這個。

+0

當navigator.notification.confirm處於活動狀態時,它不起作用來處理返回按鈕事件。 –