2

打开 navigator.notification.confirm 时如何检测返回按钮事件?后退按钮只是关闭弹窗,但是事件 document.addEventListener('backbutton', onBackKeyDown, false); 没有提出。

4

1 回答 1

0

success您传递给navigator.notification.confirmAPI 的回调中,您可以获取单击了哪个按钮的 buttonIndex。它没有记录,但如果 buttonIndex=0,那么用户要么在对话框外单击以关闭它,要么单击“后退”按钮。

例如:

  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,然后他们在对话框之外点击。如果buttonIndex===0它没有被触发,他们点击了硬件后退按钮。

我还阅读了有关使用 JQM 检测是否按下后退按钮的 StackOverflow 上的其他问题;也许你可以用这个。

于 2013-05-22T15:42:30.343 回答