I am having an issue I cannot solve. \I would like to use the android hardware buttons to control backwards movement between pages, so I have enabled pushState: true.
For the most part this works fine, one page has some modals on. I would like these to close with the back button, which they don’t the navigation works behind them.
So I got a bit of code from StackOveflow which i have added into a device ready function.
document.addEventListener('backbutton', function navigateBack() {
var mainView = app.views.main;
var leftp = app.panel.left && app.panel.left.opened;
var rightp = app.panel.right && app.panel.right.opened;
if (leftp || rightp) {
app.panel.close();
return false;
} else if ($$('.modal-in').length > 0) {
app.dialog.close();
app.popup.close();
return false;
} else if (app.views.main.router.url == '/index/') {
navigator.app.exitApp();
} else {
mainView.router.back();
}
}
, false)}
As soon as I add an event listener to the back button, all normal functions of the back button cease to work correctly.
In the above code the modals close and the back buttons work perfectly, but from the main index page, the app will not exit…
Remove the code and the back function works perfectly and the app will exit but the modals don’t close (obviously)
This part isn’t working… Is there any reason why?? Thanks
} else if (app.views.main.router.url == ‘/index/’) {
navigator.app.exitApp(); }