duanjianshen4871 2012-08-27 02:15 采纳率: 100%
浏览 1277
已采纳

如何清除iFrame的缓存?

我有一个网页,在其中,我试图刷新一个iframe。我正在尝试使用类似于输入/>按钮和javascript之类的东西来实现它,在不清除缓存的情况下,我似乎无法让iframe重新加载,只有让PHP清除缓存才可以。

更新:

下面是内联的工作实现。

    <input type="button"  onClick="javascript: var iFrame = document.getElementById('compilePreview'); iFrame.src = '<? echo ($myFile); ?>?random=' + (new Date()).getTime() + Math.floor(Math.random() * 1000000);" value="Reload Preview" />
    <iframe id="compilePreview" src="<? echo ($myFile); ?>" width="940"></iframe>

而更大的负载很快就会随之而来,按钮的作用就不大了。

    <script>
    window.onload=refreshIframe;
    function refreshIframe(){
    var iFrame = document.getElementById('compilePreview');
    iFrame.src = '<? echo ($myFile); ?>?random=' + (new Date()).getTime() + Math.floor(Math.random() * 1000000);
    }
    </script>
  • 写回答

3条回答 默认 最新

  • douhui1630 2012-08-27 02:21
    关注

    The first choice is probably to control browser caching for the iframe page from your web server either with HTTP headers or with <meta> tags (see reference).

    <meta HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
    <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
    

    If you can't change those, then you can set a .src in the iframe that has a different query parameter each time to go around caching.

    For example:

    iframeObj.src = "http://www.example.com/page/myframe.html?random=" + (new Date()).getTime() + Math.floor(Math.random() * 1000000);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题