I have a hybrid application developed with Cordova. The app is very simple, so I haven't used a framework. Almost all the pages are injected via Ajax using the jQuery's ajax()
method, and then added in the history using the HTML5 History API via the pushState()
method.
To allow the user to go back to a previously visited page (a page in the history), I've created a button. I listen for the backbutton
event as well as taps on that button and when the event is fired, I execute the following handler:
onBackButton: function() {
window.history.length === 0 ? navigator.app.exitApp() : window.history.back();
}
To be sure to have the maximum compatibility possible, I've also added history.js to the project.
It works like a charm on Android and on the iOS simulator on the Mac, but doesn't work on a real device. What happens is that iOS catch the event but the execution of the method doesn't change the page. I've already tried several methods based on previous answers on StackOverflow, but no luck. Some examples are: history.back() not working in phonegap ios build and Phonegap - navigator.app.backHistory() not working on HTML back button.
What I can try?
You can simply use,
history.go(-1);
to navigate back.
Seen this answer from a few months back? Apparently iOS has some security issues when it comes to navigating history through script alone. The answer here also includes a work around by hashing the URLs: StackOverflow Question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With