2011-06-20 37 views
0

我想阻止我的iframe被緩存。第一頁不是問題。然後我用這樣的PHP:添加時間戳到使用JavaScript的iframe中的src(防止緩存)

<iframe id="my_iframe" src="index.html#<?php echo time() ?>"></iframe> 

我遇到的問題是防止在iframe內單擊鏈接時出現chaching。例如:

<a href="newpage.html">this page will be cached</a> 

如何防止「newpage.html」的緩存?我可以以某種方式添加時間戳到src使用Java腳本?

回答

2

是你可以做到這一點,

var linksList = document.getElementsByTagName('a'); 

for(var i=0,len=linksList.length;i<len;i++) 
    linksList [i].href += '#'+new Date(); 

這個腳本應該body標籤閉幕前放置,或者應該在DOM加載後一般被調用。

現在,是不是有一個後端的方式(帶頭)要求瀏覽器不要緩存一些特定的頁面?

1

在您不希望緩存的數據的頁眉中使用此代碼。

<?php 
header("Cache-Control: no-cache"); 
header("Pragma: no-cache"); 
?>