PhoneGap询问您是要退出还是返回历史记录

时间:2013-04-23 10:26:35

标签: android cordova back-button

这是我的代码:

   function onLoad(){
                alert("onLoad");
                document.addEventListener("deviceready",onDeviceReady, true);
             }

             function onDeviceReady(){
                navigator.notification.alert("PhoneGap is working!!");
                document.addEventListener("backbutton", onBackKeyDown, false);
             }


            function onBackKeyDown(e) {        
                    navigator.notification.alert("PhoneGap handle back button click!!!");
                     /* want you to go back???
                          if yes go back or exit app
                     */
            }

你能帮帮我吗

/* want you to go back???

   if yes go back or exit app

*/

非常感谢。

2 个答案:

答案 0 :(得分:0)

function showAlert() {
                    navigator.notification.confirm(
                        'Vuoi uscire dall\'applicazione?',  // message
                        onConfirm,              // callback to invoke with index of button pressed
                        'Chiudere?',            // title
                        'Chiudi app,Annulla'          // buttonLabels
                    );
                }

            function onConfirm(button) {
                if(button==1)           
                    navigator.app.exitApp();
            }

答案 1 :(得分:0)

navigator.app.exitApp()无法在iOS上运行:(

票数: https://stackoverflow.com/a/14423091/826822