3

When I navigate back using the browser back button in Chrome/ Firefox my website works just as expected (the same as it would if loaded without navigating backward).

In Safari after navigating back I can't get any 'on load' type event to fire whether the standard document ready or some hackaround found on here on StackOverflow. I'm not doing anything special, I just really need to call:

$( document ).ready(function() {
  // analyticsEvent();
  // startAnimation();
  // etc();
});

Has anyone encountered the same problem?

ztech
  • 560
  • 5
  • 13
  • i Think that's happen because safari uses cached javascript, maybe use pageshow method insted of .ready will work – Nico Apr 20 '16 at 17:17

1 Answers1

11

Try this

$(window).bind("pageshow", function(event) {
    if (event.originalEvent.persisted) {
        window.location.reload() 
    }
});
Milan
  • 829
  • 8
  • 12
  • You're the best! Totally works. Additionally, I just called the functions I want from inside the if statement (instead of reloading). Thanks a bunch. – ztech Apr 20 '16 at 19:20