2012-02-28 64 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