注:在jQuery 页面写一个按钮,然后添加下面的javascript。
让phonegap 返回键后按 确定才退出应用!
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
function onDeviceReady() {
// 注册回退按钮事件监听器
document.addEventListener("backbutton", onBackKeyDown, false); //返回键
}
function onConfirm(button) {
//alert('You selected button ' + button);
if(button==1) navigator.app.exitApp(); //选择了确定才执行退出
}
// Show a custom confirmation dialog
//
function onBackKeyDown() {
navigator.notification.confirm(
'按确定退出程序!', // message
onConfirm, // callback to invoke with index of button pressed
'确定要退出程序吗?', // title
'确定,取消' // buttonLabels
);
}
本文探讨了在手机应用中如何通过PhoneGap框架利用事件监听器实现返回键后弹出确认对话框,确保用户在退出应用前进行确认操作。

126

被折叠的 条评论
为什么被折叠?



