Stop Exit on Back Button Android in PhoneGap - Build

后端 未结 2 1811
一向
一向 2020-12-17 03:19

I\'m building my application through PhoneGap Build online. I want to change the default behavior of Back Button

$(document).ready(function(         


        
2条回答
  •  清酒与你
    2020-12-17 03:53

    Its said in Cordova API documentation that

    Typically, you will want to attach an event listener with document.addEventListener once you receive the PhoneGap 'deviceready' event.

    So change your code like this

    document.addEventListener("deviceready", onDeviceReady, false);
    
    // PhoneGap is loaded and it is now safe to make calls PhoneGap methods
    function onDeviceReady() {
        // Register the event listener
        document.addEventListener("backbutton", onBackKeyDown, false);
    }
    
    // Handle the back button
    function onBackKeyDown() {
             //Your backbutton code
    }
    

提交回复
热议问题