我正在尝试更改Android设备上后退按钮的行为。我正在使用Cordova并编写了以下有效的代码:
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
//device APIs are available
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
//Backbutton
function onBackKeyDown() {
location.href = "index.html";
}
现在,我看到的是,当我双击后退按钮时,函数onBackKeyDown()将被忽略。 有没有办法解决这种情况?
修改
// Wait for device API libraries to load
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
//device APIs are available
function onDeviceReady() {
document.addEventListener("backbutton", onBackKeyDown, false);
}
document.addEventListener("backbutton", function (e){
e.preventDefault();
location.href = "index.html";
}, false);
答案 0 :(得分:2)
尝试阻止默认的backbutton
事件以及自定义导航。像这样:
document.addEventListener("backbutton", function (e){
e.preventDefault();
location.href = "index.html";
}, false);
您还可以查看以下代码:https://lloydzhou.github.io/project/2014/04/30/phonegap-exit-on-double-click-backbutton。它捕获单击和双击。