How to disable phone button back on Android using jquerymobile, phonegap

Can someone please tell me how to disable the Android button back (this is the button found on all Android phones).

I am using jQuery mobile with PhoneGap. I find it online in the Cordoba documentation, but it does not work for me. The back button event is not even logged.

function onLoad() {
    console.log("**** INSIDE ONLOAD FUNCTION *****");
    document.addEventListener("backbutton", onBackKeyDown, false);   
}

// Handle the back button
function onBackKeyDown() {

    // Pressing the back button does not print this message.
    console.log("**************** INSIDE BACK BUTTON *************");
}
+5
source share
2 answers

I used backKeyDownand it works for me:

function onDeviceReady() {
        document.addEventListener("backbutton", backKeyDown, true);
        console.log("PhoneGap is ready");
    }

    function backKeyDown(d) {
        navigator.app.exitApp(); // To exit the app!
        e.preventDefault(); // to disable the back
    }

make sure that PhoneGap is ready!

Update: You can leave the handler empty until you disable it.

+13
source
sometimes you can get blocking Back button, sometimes not.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    document.addEventListener("backbutton", function (e) {
        e.preventDefault();
    }, false );
}
0
source

All Articles