9

So I'm trying to redirect the user back one level in the history on an iPhone HomeScreen App, but it's simply just not firing for some reason.

Current code is as follows window.history.go(-1)

I've also tried various other version window.history.back(), history.go(-1), but no luck yet. I can't wrap my head around how to implement the pushState, so I haven't tried that approach yet, but it's quite annoying how incredibly bad the homescreen app stuff is made.

Atleast you're able to debug with Safari.

Nict
  • 3,066
  • 5
  • 26
  • 41
  • Does it work if you access the web app through Safari? Do you get any errors when you make the call? Can you post the event hookup and the code that makes the call to `window.history.go`? – rusmus Feb 20 '14 at 09:59
  • I suggest you use a library like [historyjs](https://github.com/browserstate/history.js/) as it aims to provide a consistent cross-browser interface for html5 history. – Ryan Wheale Feb 20 '14 at 23:28
  • Um... What type of app is this? I literally loaded up my own homescreen app and both `window.history.back()` and `window.history.go(-1)` worked when I entered them in the console. – okcoker Feb 21 '14 at 04:26

2 Answers2

6

You can debug mobile safari, but unfortunately you need a mac.

If not, try this:

  1. Make sure your code is working and no errors on desktop safari;
  2. Check if you are actually making the call by adding an alert("history() called") in place of the history(-1) code;
  3. Is it in a link that has a default behavour to navigate to another page? If so, you need a event.preventDefault() or at least a return false; after the history() call.

iOS simulator safari debugger

Bas Slagter
  • 9,831
  • 7
  • 47
  • 78
Chris Gunawardena
  • 6,246
  • 1
  • 29
  • 45
6

Try something like:

<a href="javascript:history.go(-1)">Go back</a>
ayunami2000
  • 441
  • 6
  • 10