Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

history.back doesn't work on iOS using Cordova

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?

like image 858
Aurelio De Rosa Avatar asked Jun 22 '14 15:06

Aurelio De Rosa


2 Answers

You can simply use,

history.go(-1);

to navigate back.

like image 163
totten Avatar answered Sep 19 '22 01:09

totten


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

like image 27
James Hunt Avatar answered Sep 22 '22 01:09

James Hunt