2
window.history.go(-1)

I am using this JS function, it seems to be working perfectly in Chrome and Firefox but seems like it is not working in Safari... Does anybody know how to make it work in Safari?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    [Don't know if this is any use - it's quite old](https://stackoverflow.com/questions/6161701/is-history-api-broken-on-ios-location-bar-doesnt-update-on-pushstate). – Andy Jan 30 '18 at 11:18
  • Does this answer your question? [Is History API broken on iOS? (Location bar doesn't update on pushState)](https://stackoverflow.com/questions/6161701/is-history-api-broken-on-ios-location-bar-doesnt-update-on-pushstate) – Brian Tompsett - 汤莱恩 Mar 28 '20 at 21:57

2 Answers2

0

You can try the following:

Check if you are actually making the call by adding an alert("history() called") in place of the history(-1) code;

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.

Edit: Andy mentioned this link: Is History API broken on iOS? (Location bar doesn't update on pushState) Maybe you can use that.

Edwin van der V
  • 238
  • 2
  • 8
0

If you don't want to use event.preventDefault() method.Then

<script>
 function gofunc() {
   history.go(-1);
 }
</script>

The call the function:

<a href="javascript:gofunc()">Nav Element</a>
Jahid Hasan
  • 224
  • 1
  • 15