我有一个网页,我试图在其中刷新 iFrame。我正在尝试用 <input />
之类的东西来做按钮和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>
当然,onload 很快就会跟进,消除了对按钮的需要。
<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>
最佳答案
第一个选择可能是使用 HTTP header 或 <meta>
控制来自 Web 服务器的 iframe 页面的浏览器缓存。标签(参见 reference )。
<meta HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
如果你不能改变这些,那么你可以设置一个.src
在 iframe 中每次都有不同的查询参数来绕过缓存。
例如:
iframeObj.src = "http://www.example.com/page/myframe.html?random=" + (new Date()).getTime() + Math.floor(Math.random() * 1000000);
关于php - 如何清除 iFrame 的缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12135544/