Friday, September 7, 2012

Force iPad/iPhone and iEtcetera to reload pages



Found very useful information on Stack Overflow by South African BrutallDev.

I found absolutely NOTHING else in the whole internet universe to successfully fix the problem on iPads and other iOS devices, where web pages are not reloaded upon a person returning to them via the Safari browser back button. No acceptable solution anyway.

Like SQL Authority Pinal Dave, who's been The Man for years as the go-to guy for SQL issues, I nominate BrutalDev for that honor regarding browser back and forth.

 Just in case that Stack Overflow page ever disappears, or changes urls, Brutal's Javascript snippet is as follows:

if ((/iphone|ipod|ipad.*os 5/gi).test(navigator.appVersion)) {
  window.onpageshow = function(evt) {
    // If persisted then it is in the page cache, force a reload of the page.
    if (evt.persisted) {
      document.body.style.display = "none";
      location.reload();
    }
  };
}

Stick it in script tags or a js file as you please.
I also added a blank onunload to the body tag as he suggested for older iOS.

No comments:

Post a Comment