我已按照Cordova docs中的示例代码覆盖设备后退按钮(使用ES6),但它无法按预期工作:
const onBackButtonPress = () => {
console.log('pressed');
};
document.addEventListener('backbutton', onBackButtonPress, false);
当我在Android设备上运行应用程序时,我的覆盖代码会被调用,但应用程序也会退出,就好像还调用了默认的后退按钮操作一样 .
How can I prevent the app from exiting when the back button is pressed?
我已经尝试将 e.preventDefault()
添加到 addEventListener
的回调函数中
在 deviceready
事件被解雇后我正在这样做 .
我正在使用Cordova 7.0.1,我的平台是cordova-android 6.2.3
2 回答
我在我的应用中使用此代码:
注意,在device is ready时运行此代码
我使用如下: