1

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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
fat fantasma
  • 7,483
  • 15
  • 48
  • 66
  • possible duplicate of [Mobile Safari back button](http://stackoverflow.com/questions/11979156/mobile-safari-back-button) – Mika Tuupola Nov 29 '13 at 20:12

2 Answers2

0

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

  • As far as I can tell that doesn't work either. On mobile Safari it's using the cache and not even executing any html scripts, etc. Basically, on ios Safari I don't want to use their BFcache. All other browsers handle it differently. any more ideas? – fat fantasma Sep 16 '13 at 20:36
0

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

Dazel
  • 1
  • 1