Javascript terminates execution in iframe after clicking a button in mobile safari

I have a webpage designed for mobile phones that includes an iframe with links that open on the parent target.

In Safari on iOS 5.0.1, when the user clicks the link, then uses the back button to return to the page, javascript stops executing in the iframe.

A simple demonstration to illustrate the problem:

Click the link, confirm the notification and use the "Back" button. The second time you click the link, a warning will not appear.

index.html

<html> <body> <iframe src="iframe.html"></iframe> </body> </html> 

iframe.html:

 <html> <body> <a target="_parent" onclick="alert('Click')" href="http://www.google.com"> Link </a> </body> </html> 

I'm running out of ideas about what might be causing this. Does anyone run up to this?

+7
source share
3 answers

I ran into the same problem. It seems iPad Safari instantly displays the page, and when you return to it using the back button, it downloads that snapshot and javascript code is not executed.

This seems to be related to this problem: http://www.mac-forums.com/forums/internet-networking-wireless/257631-safari-ipad-back-button-generates-old-info.html

Very annoying. I have not found a solution yet.

+2
source

read the answer Problems with page cache in iOS 5 Safari when navigating back / unloading an event .

The answer that worked for me was this:

 <body onunload=""> ... <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> 
+2
source

All Articles