Phonegap Android Back Button - close app with back button on homepage

后端 未结 4 1075
忘了有多久
忘了有多久 2020-12-02 06:19

I am developing a Android app using Jquery Mobile/Phonegap. I have the following code to control the phone\'s back button:

document.addEventListener(\"backbu         


        
4条回答
  •  既然无缘
    2020-12-02 07:07

    If you don't want to use jQuery Mobile, change $.mobile.activePage.is('#homepage') to document.getElementById('#homepage') on @Spadar Shut answer, as on following code:

    document.addEventListener("deviceready", onDeviceReady, false);
    
        function onDeviceReady(){
            document.addEventListener("backbutton", function(e){
               if(document.getElementById('#homepage')){
                   e.preventDefault();
                   navigator.app.exitApp();
               }
               else {
                   navigator.app.backHistory()
               }
            }, false);
        }
    

    Through this way, don't need to download Jquery Mobile gibberish only for this purpose. Also, activePage is deprecated as of JQuery mobile 1.4.0 and will be removed from 1.5.0. (Use the getActivePage() method from the pagecontainer widget instead)

提交回复
热议问题