Take the 2-minute tour ×

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.


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


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

I'm running out of ideas of what could be causing this. Has anyone run in to this?

share|improve this question
add comment

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

share|improve this answer
add comment

check out the answer to Problems with Page Cache in iOS 5 Safari when navigating back / unload event not fired.

The answer that worked for me was to do the following:

<body onunload="">
<script type="text/javascript">
  window.onpageshow = function(evt) {
    if (evt.persisted) {
       document.body.style.display = "none";
share|improve this answer
FYI--this does not work if you apply this to the page inside the iframe, it must be on the overall page hosting the iframe. Or, it could be because my iframe is really embedded within another iframe. Yes, I'm using a third party component. –  subkamran Sep 5 '13 at 15:38
Yes, this definitely needs to be on the page that includes the iframe. –  DrewB Oct 24 '13 at 22:28
add comment

Your Answer


