Search code examples
c#javascriptcsscordovawindows-phone

Windows Phone PhoneGap app back button issue


I am developing Windows Phone PhoneGap app. When clicking hardware back button, It is going to the previous page using history.go(-1); But when I am in initial page and click the back button It is navigating to the same page instead of killing the application. Any help is appreciated.


Solution

  • To configure back button you can use these functions:

    // for exit app
    navigator.app.exitApp();
    
    // for back hsitory use
    navigator.app.backHistory()
    

    complete code :

    document.addEventListener("deviceready", onDeviceReady, false);
    
    function onDeviceReady(){
        document.addEventListener("backbutton", function(e){
           if($.mobile.activePage.is('#home')){
               e.preventDefault();
               navigator.app.exitApp();
           }
           else {
               navigator.app.backHistory()
           }
        }, false);
    }