gpt4 book ai didi

javascript - Phonegap 后退按钮我 android 没有捕获

转载 作者:行者123 更新时间:2023-12-03 08:05:11 24 4
gpt4 key购买 nike

我正在开发 Phonegap 应用程序。应用程序已准备就绪,现在我想在按下硬件后退时添加后退按钮事件(在 Android 中)。

我浏览了许多链接,但没有成功。

任何人都可以告诉我在 Android 的 Cordova 应用程序中捕获后退按钮事件的确切方法是什么。我的代码如下。

index.html

 <script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);

alert("====device ready----");
// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
alert("===back button initializing==");
}

// Handle the back button
function onBackKeyDown() {
alert("====BACK PRESSED====");
}
</script>

当我按后退按钮时,没有任何反应。

谁能告诉我我犯了什么错误。拜托,已经浪费了6个小时了。 :(

最佳答案

make sure you have installed codova dialogs plugin:-

For example:-

cordova plugin install org.apache.cordova.dialogs

and also add following line:-

document.addEventListener("backbutton", backKeyDown, true);
navigator.app.overrideBackbutton(true);
function backKeyDown() {//code here
}

关于javascript - Phonegap 后退按钮我 android 没有捕获,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34410326/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com