2014-05-06 47 views
4

我在同一目錄中有三個簡單的HTML文件:怪異的行爲時,頁面刷新

的index.html

<html> 
     <head> 
      <title>Page 1</title> 
     </head> 
     <body> 
      <iframe src="page2.html"></iframe> 
     </body> 
    </html> 

page2.htmlpage3.html(大約相同的內容)

<html> 
     <head> 
      <title>Page 2</title> 
     </head> 
     <body> 
      This is the content of page 2 
     </body> 
    </html> 


    <html> 
     <head> 
      <title>Page 3</title> 
     </head> 
     <body> 
      This is the content of page 3 
     </body> 
    </html> 

index .html包含指向其他兩個HTML文件之一的。

當我第一次加載index.html時,它按預期工作並打印出「這是第2頁的內容」。但是,當我將src屬性更改爲「page3.html」並重新加載頁面時,沒有任何更改。它一直告訴我「這是第2頁的內容」,儘管它應該加載第3頁。

但是,當我關閉該選項卡並重新打開該頁面(index.html)時,它將起作用並打印出「這是第3頁的內容」。但是,當我將其更改回page2.html時,它會粘貼到第3頁。

這很奇怪。我猜瀏覽器正在緩存頁面,或類似的東西。

當我添加:

<script> 
    document.write(document.querySelector("iframe").src); 
</script> 

然後,打印正確的文件位置。 (但iframe的內容仍然是錯誤的。)

這意味着即使瀏覽器檢測到文件已更改,它甚至不會在頁面重新加載時重新加載iframe

什麼會導致這種奇怪的行爲?我該如何解決它?

謝謝。

P.S.使用Firefox 29測試。

P.S. (2)所有的文件都在我的電腦上,我沒有在遠處的服務器上讀取它們。

+0

https://bugzilla.mozilla.org/show_bug.cgi?id=356558 –

回答

2

嘗試添加類似:

document.getElementById(FrameID).contentDocument.location.reload(true); 

這迫使iframe來加載每個頁面重新加載時間。

編輯:我試着用Chrome瀏覽器,它運行良好,即使沒有腳本。

0

如果你在頻繁變更此iframe計劃,我會動態創建iframe中,通過Javascript(必須提到 - 你會在iframe的鬆動FF緩存):

HTML代碼:

<!doctype html> 
<html> 
    <head> 
     <title>Page 1</title> 
    </head> 
    <body> 
     <div id="iframe_wrapper"></div> 
    </body> 
</html> 

JavaScript代碼:

document.addEventListener("DOMContentLoaded", function(event) { 
    var iframeWrapper = document.getElementById("iframe_wrapper"); 
    var iframe = document.createElement("iframe"); 
    iframe.src="http://www.bing.com/"; 
    iframe.width = "400"; 
    iframe.height = "400"; 

    iframeWrapper.appendChild(iframe); 
});