Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I disable the phone's back button in Android using Jquerymobile, PhoneGap

Could someone please tell me how to disable Android's back button (That is the back-button found on all Android phones).

I am using Jquery mobile with PhoneGap. I find this online in the Cordova documentation, but this does not work for me. Back button event is not even registering.

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 *************");
}
like image 565
user1478810 Avatar asked Sep 23 '12 23:09

user1478810


1 Answers

I used backKeyDown and 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 to disable it

like image 88
Ouadie Avatar answered Sep 22 '22 15:09

Ouadie