如何在Android中使用Jquerymobile,PhoneGap禁用手机的后退按钮 [英] how do I disable the phone's back button in Android using Jquerymobile, PhoneGap

查看:120
本文介绍了如何在Android中使用Jquerymobile,PhoneGap禁用手机的后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何禁用Android的后退按钮(即所有Android手机上的后退按钮)。



我使用的是PhoneGap的Jquery mobile。我在Cordova的文档中找到这个,但是这对我没有用。后退按钮事件甚至未注册。

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

//处理后退按钮
function onBackKeyDown(){

//按后退按钮不打印此消息。
console.log(**************** INSIDE BACK BUTTON *************);
}


解决方案

c> backKeyDown ,它适用于我:

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

function backKeyDown(d){
navigator.app.exitApp(); //退出应用程序!
e.preventDefault(); //禁用后退
}

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

解决方案

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

这篇关于如何在Android中使用Jquerymobile,PhoneGap禁用手机的后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆