2012-02-28 90 views
5

我試圖創建一個頁面,當刷新時,它將從URL列表中隨機加載一個URL。到目前爲止,我發現最好的方法是讓PHP從文件中隨機獲取行,然後將其加載到iframe中。這也允許我在頂欄上有一個關閉按鈕,允許加載到iframe的任何頁面都可以突破。Firefox在動態iframe中加載緩存

我遇到的問題是,在一對夫婦重新加載iframe剛開始恢復到緩存,並將不會加載任何新的Firefox後。我猜這是一個緩存問題,因爲按Ctrl + F5將使iframe加載一個新頁面。

我試過把一堆反高速緩存meta標籤以及我在this文章中找到的JavaScript的一片。

到目前爲止沒有任何工作。有誰知道一個很好的解決方法或在我的代碼中看到錯誤(我是一個新手)。

感謝您的幫助!

下面是代碼:

</html> 

<head> 
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache"> 
<META HTTP-EQUIV="Pragma" CONTENT="no-cache"> 
<meta http-equiv="expires" content="FRI, 13 APR 1999 01:00:00 GMT"> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 

<script type="text/javascript"> 

function Ionload() 
{ 

$(parent.document).find("iframe").each(function() { 
    // apply the logic only to the current iframe only 
    if(this.contentDocument == window.document) { 
     // if the href of the iframe is not same as 
     // the value of src attribute then reload it 
     if(this.src != location.href) { 
     this.src = this.src; 
     } 
    } 
}); 

} 
</script> 

<?php 

class MyClass 
    { 
    function GetLine() 
     { 
      global $line; 

      srand ((double)microtime()*1000000); 
      $f_contents = file ("urlz"); 
      $line = $f_contents[array_rand ($f_contents)]; 

     } 

    function PrintVar() 
     { 
      global $line; 
      print $line; 
     } 
    } 

MyClass::GetLine(); 

?> 

<style type="text/css" media="all"> 
    html, body { 
     height: 100% 
    } 
    body { 
     margin: 0; 
     overflow: hidden; 
    } 
    #topbar { 
     height: 50px; 
     width: 100%; 
     border-bottom: 3px solid #666 
    } 
    #page { 
     height: 100%; 
     width: 100%; 
     border-width: 0 
    } 
</style> 

</head> 
<body> 

<div id="topbar"> 

<a href=<?php MyClass::PrintVar();?> target="_top">close</a> 

</div> 

</body> 

<iframe id="page" name="page" onload="Ionload()" src=<?php MyClass::PrintVar();?> frameborder="0" noresize="noresize"></iframe> 

</html> 

更新:

與GGG一些幫助,我得到它固定。這裏是改變功能:

function GetLine() 
    { 
     global $newline; 

     srand ((double)microtime()*1000000); 
     $f_contents = file ("urlz"); 
     $line = $f_contents[array_rand ($f_contents)]; 
     $newline = $line . "?foo=" . rand(); 

    } 

我有一個隨機數,而不是一個序列去,因爲我不知道如何從一個重裝攜帶序列到另一個,但這個工程。

我也注意到,如果firefox在頁面加載後不到兩秒鐘內刷新,問題仍然存在,但我可以忍受。

回答

3

嘗試將一個虛擬查詢字符串粘貼到URL上,以便瀏覽器被迫跳過緩存。

例如,而不是加載www.google.com,加載www.google.com?foo=N其中N是您隨每個加載增加的數字。

+0

有沒有辦法讓PHP做到這一點,因爲它從文件中拉鍊接?我對PHP很陌生。這實際上是我第一次嘗試使用它。謝謝。 – silverMASH 2012-02-28 04:13:39

+0

是的,您可以在PHP中使用'.'(點)運算符來進行字符串連接。 – 2012-02-28 04:16:14

+0

謝謝!我想我已經開始工作了。解決方案在原文中。 – silverMASH 2012-02-28 05:13:58