2013-05-22 235 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处于活动状态时,它不起作用来处理返回按钮事件。 –