scottjehl / Device-Bugs

Just a collection of quirks and issues that occur on browser platforms (particularly those unlikely to update)
864 stars 19 forks source link

iOS disables Javascript in iframes when navigating back to a page #38

Open kamranayub opened 11 years ago

kamranayub commented 11 years ago

The issue is documented here:

http://stackoverflow.com/questions/9094398/javascript-stops-executing-in-iframe-after-back-button-is-pressed-in-mobile-safa

The workaround is to add this to the page hosting the iframes (note: you do not need the body attribute on iOS 5.1+):

<script type="text/javascript">
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();
    }
  };
}
</script>

I've confirmed this works around the issue on iOS 5.1+.