0

We have a few iOS clients complaining that the "back" button we implemented in the AngularJS app doesn't always work. The back button is just an image that performs a $window.history.back(). I've read that using window.history.go(-1) is preferred but this isn't the Angular way.

Does anyone know of any problems in iOS with $window.history.back? And if so, what is the correct way of implementing this in AngularJS?

Kostas Siabanis
  • 2,989
  • 2
  • 20
  • 22
Steven Lemmens
  • 1,441
  • 3
  • 17
  • 30
  • Possible duplicate of [Cordova - window.history.back() not working on HTML back button in iOS 9](https://stackoverflow.com/questions/32761206/cordova-window-history-back-not-working-on-html-back-button-in-ios-9) – Ramesh Rajendran May 30 '17 at 13:48
  • I'm using angular#1.5.1, having the same ios issue that, $window.history.go(-1) is not working in ios 10.2.1 – CodeTweetie May 31 '17 at 09:42
  • We ended up removing window.history.back() from our app and solved it in another way. Check this question: https://stackoverflow.com/questions/16635381/angular-ui-router-get-previous-state. In the event of "stateChangeSuccess", we would store the "fromState" (= the previous state) in a variable and then use $state.go(vm.fromState) to return to the previous page when the back-button is clicked. This works really well for us. – Steven Lemmens May 31 '17 at 15:06

1 Answers1

0

I had a very similar issue with our web wrapper app ( webview pointed to an iframe ).

Our 'back button' is a simple call to history.back(1);.

Worked perfectly expect when loading via UIWebView on apple devices.

We noticed that once we started navigating 2 or more hops into the site, the button worked.

Easiest method i found was to set a timeout for a page click by half a second, at the end of the $(document).ready.

setTimeout(function() {
        $(".nav-home-logo").click();
}, 5000);

We already had an onclick event for .nav-home-logo that called:

$("iframe").attr("src", "https://your.website.here?foo=" + Math.random());

The cache buster seems to help.

I believe its related to the issues described here.

Simon.
  • 1,886
  • 5
  • 29
  • 62