让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
        );
    }

相关推荐