Reputation: 3915
Is there any way in cordova 3.x or 4 to allow the backbutton event to propagate to the "normal" handler(s), like you can do with most other user interface events (click, touch etc).
Our problem is that we need to disable the backbutton under certain circumstances, but allow it to perform normal back navigation the rest of the time.
Currently we have added a global click listener, that examines the current situation, and then adds/removes the backbutton listener, depending on what it finds. This is fine while events are user driven, but some situations results in the app (for example) popping up a 2nd or 3rd dialog (which is one of the places where the backbutton must be disabled) - this is causing a ruckus.
Thanks.
Upvotes: 1
Views: 174
Reputation: 546
if suppose you want to exit from your app only if you are on a home page.then you have to write following line in DeviceReady function.
document.addeventlistener("backbutton", onBackButton,false);
function onBackButton(){
if($.mobile.activePage.attr("id") == "homepage"){
navigator.app.exitApp();
}
else{
navigator.app.backHistory();
}
Upvotes: 1
Reputation: 2427
You have to be careful. Your application might be violating the application guidelines for app stores. The microsoft app store doesn't allow you to prevent the hardware back button from going back, for instance.
In these cases where the user can't proceed or go back, the suggested behavior is to exit the application, preferably after prompting the user that clicking back again will exit the application.
Upvotes: 2