打开navigator.notification.confirm时如何检测后退按钮事件?返回按钮只是关闭弹窗,但是事件 document.addEventListener('backbutton', onBackKeyDown, false);没有提出。
最佳答案
在传递给 navigator.notification.confirm
API 的 success
回调中,您可以获取单击了哪个按钮的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
但它没有被触发,他们就会点击硬件后退按钮。
我还阅读了 StackOverflow 上有关使用 JQM 检测后退按钮是否被按下的其他问题;也许你可以用这个。
关于jquery - 如何检测后退按钮事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16694083/