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

感情迁移 提交于 2019-12-23 11:58:21

问题


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 *************");
}

回答1:


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




回答2:


sometimes you can get blocking Back button, sometimes not.

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


来源:https://stackoverflow.com/questions/12557249/how-do-i-disable-the-phones-back-button-in-android-using-jquerymobile-phonegap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!