[英]Android back button to work with navigation in PhoneGap app
I'm building a PhoneGap mobile app with Onsen UI on the top. 我正在使用顶部的Onsen UI构建PhoneGap移动应用程序。
I want the basic android back button to work with the onsen navigator and ons-sliding-menu, so it does what it's supposed to do. 我希望基本的android后退按钮可以与onsen导航器和ons-sliding-menu一起使用,因此它可以执行预期的操作。
I don't want it to close the app. 我不希望它关闭该应用程序。
To prevent the back button from closing the app, I used the following code in the index.js files onDeviceReady event: 为了防止后退按钮关闭应用程序,我在index.js文件的onDeviceReady事件中使用了以下代码:
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {
e.preventDefault();
}
What changes should I make, for the back button to work properly? 为了使后退按钮正常工作,我应该进行哪些更改?
Checking the Documentation I found that to control navigation you could use the pushPage and popPage functions. 查看文档我发现可以使用pushPage和popPage函数来控制导航。
So maybe try something like this: 所以也许尝试这样的事情:
document.addEventListener("backbutton", onBackKeyDown, false);
function onBackKeyDown(e) {
e.preventDefault();
yourNavigator.popPage('page.html');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.