php - Firefox 在动态 iframe 中加载缓存

标签 php javascript firefox caching

我正在尝试创建一个页面,该页面在刷新时会从 URL 列表中随机加载一个 URL。到目前为止,我发现执行此操作的最佳方法是让 PHP 从文件中随机抓取该行,然后将其加载到 iframe 中。这也允许我在顶部栏上有一个关闭按钮,允许加载到 iframe 中的任何页面跳出。

我遇到的问题是,在 firefox 中,在几次重新加载 iframe 后,iframe 才开始恢复为缓存,并且不会加载任何新内容。我猜这是缓存问题,因为按 Ctrl+F5 将使 iframe 加载新页面。

我已经尝试放入一堆反缓存元标记以及我在 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 在页面加载后不到两秒内刷新,问题仍然存在,但我可以接受。

最佳答案

尝试在 URL 上附加一个虚拟查询字符串,以便浏览器强制跳过缓存。

例如,不是加载 www.google.com,而是加载 www.google.com?foo=N,其中 N 是一个每次加载时增加的数量。

关于php - Firefox 在动态 iframe 中加载缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9476140/

相关文章:

html - 从 Firefox Desktop 中的 HTML5 <video> 元素中删除 "foggy screen"/white 覆盖

php - 如何漂亮地打印已删除源元素的 XSLT 结果文档?

javascript - 如何检测图像加载失败,如果失败,尝试重新加载直到成功?

javascript - ASP.NET 的首选日历

javascript - SPA 的 Shopify 嵌入式应用程序身份验证流程帮助

xml - 为什么 E4X 被弃用并从某些浏览器中删除?

google-chrome - 与 Firefox 中 Chrome 的 native 客户端消息传递类似的技术?

PHP:HTTP_X_REQUESTED_WITH 与 HTTP_X_REQUEST_WITH

php - 如何在 MYSQL 中回显存储为数组的值?

php - 强制自动加载特定类