Reputation: 13856
I am working with phonegap and jquery mobile but am having problems with going back on pages. There are four pages:
Splash
Login
Main
SubMain
So Lets say the flow goes like this always hit the splash screen first. If a user has never logged before, they are shown the login screen, if they have then they are shown the main page. Here's a scenario:
A new user will navigate like this:
Splash
Login
Main
SubMain
Now from Submain screen, if they want to exit they will hit the back button until the they exit. However this route will take them through the Login page and the Splash screen again, when I want them to exit the app when they hit back on the main screen.
Is there anyway to make the user exit when pressing back on Main?
I realize I could avoid this by disabling the back button and adding an exit button.
I'm not sure if this matters or not, but all my pages are in one single html file separated by divs with the data-role="page"
attribute
Upvotes: 0
Views: 536
Reputation: 2688
I think navigator.app.exitApp()
is what you're looking for. As we keep track of the history manually our helper function looks similar to this:
function backKeyDown(){
if(historyContainsInfo(){
popHistory();
}else{
navigator.app.exitApp();
}
}
and is registered via document.addEventListener("backbutton", backKeyDown, true);
Upvotes: 1