1
votes

Safari and Safari ios mobile uses the bfcache when a user clicks the 'back button' to return to the previous html page. No other browsers mobile or desktop have this behavior from what I can find. I have googled and have found many people complaining of the same thing but without any solution with Safari ios. I did find this fix for Safari Desktop (tested on windows) but it does not work for Safari ios.

 window.onbeforeunload = function()
  {
    // This function does nothing.  It won't spawn a confirmation dialog
    // But it will ensure that the page is not cached by the browser.
  };

  window.onunload = function()
  {
    // Needed in OP in order to avoid caching. May also be needed in Safari.
  };

Does anybody know how to do it for Safari ios?

The reason I want to do this is that I have a spinner indicator as well as a modal in certain cases displayed before I move on to the next web page. If the user clicks the back button Safari ios uses the cache and the spinner and/or modal are still there.

Any ideas?

2
possible duplicate of Mobile Safari back button - Mika Tuupola

2 Answers

0
votes

What's about hiding spinner div in the window.onbeforeunload callback? Browser cache is actually a cool thing...

0
votes

You can use this function to detect pageshow event. The pageshow tells you whether it's coming from bfcache.

Reference: https://developer.mozilla.org/en-US/docs/Working_with_BFCache

window.addEventListener('pageshow', function(event) { 
  doSomething(); 
}

https://developer.mozilla.org/en-US/docs/Working_with_BFCache