2012-02-01 111 views
7

我有一個專門用於手機的網頁,其中包含一個鏈接在父目標中打開的iframe。在移動Safari中按下後退按鈕後,Javascript停止在iframe中執行

在iOS 5.0.1的Safari中,當用戶點擊一個鏈接,然後使用返回按鈕返回頁面時,JavaScript停止在iframe內執行。

一個簡單的演示來說明這個問題:

點擊鏈接,確認該警報並使用返回按鈕。第二次點擊鏈接警報不會顯示。

的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> 

我跑出來的東西可能會造成這個想法。有沒有人跑過來呢?

回答

2

退房答案Problems with Page Cache in iOS 5 Safari when navigating back/unload event not fired

爲我工作的答案是做到以下幾點:

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

僅供參考 - 這不,如果你將此到iframe中的頁面工作,它必須是託管的iframe的整個頁面, 。或者,這可能是因爲我的iframe確實嵌入了另一個iframe。是的,我正在使用第三方組件。 – kamranicus 2013-09-05 15:38:34

+1

是的,這絕對需要在包含iframe的頁面上。 – DrewB 2013-10-24 22:28:17