Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript stops executing in iframe after back button is pressed in mobile safari

I have a web page intended for mobile phones that includes an iframe with links that open in the parent target.

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

A simple demo to illustrate the problem:

Click the link, confirm the alert and use the back button. The second time you click the link the alert won't show.

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 of what could be causing this. Has anyone run in to this?

like image 303
mikgra Avatar asked Feb 01 '12 10:02

mikgra


1 Answers

I have ran into the same issue. It seems that iPad's Safari snapshots the page and when you go back to it using the back button, it loads that snapshot and javascript code is not being executed.

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

Very annoying. I haven't found a solution yet.

like image 125
Victor Levin Avatar answered Sep 30 '22 08:09

Victor Levin