scottjehl/Device-Bugs

iOS disables Javascript in iframes when navigating back to a page

Opened this issue · 0 comments

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+.