firefox上的Iframe src缓存问题

firefox上的Iframe src缓存问题,iframe,Iframe,我有一个带有随机scr属性的iframe元素。当我每次刷新页面时,iframe应该根据src属性加载具有不同查询参数的页面。但是在firefox中,如果我尝试在iframe中加载动态URL,它总是执行第一次执行的URL,即使src属性动态更改。查询参数也没有正确传递。那么,我怎样才能解决这个问题呢 例如: PHP中的代码执行一次并将内容发送到浏览器。刷新页面时,代码不会在服务器中再次运行,因为它由缓存提供服务。因此,iframe的src使用相同的随机数 为了避免这种情况,您需要禁用原始页面(而不

我有一个带有随机scr属性的iframe元素。当我每次刷新页面时,iframe应该根据src属性加载具有不同查询参数的页面。但是在firefox中,如果我尝试在iframe中加载动态URL,它总是执行第一次执行的URL,即使src属性动态更改。查询参数也没有正确传递。那么,我怎样才能解决这个问题呢

例如:


PHP中的代码执行一次并将内容发送到浏览器。刷新页面时,代码不会在服务器中再次运行,因为它由缓存提供服务。因此,iframe的src使用相同的随机数


为了避免这种情况,您需要禁用原始页面(而不是iframe)的缓存。或者您可以在客户端(使用javascript)生成随机数,这样每次都是唯一的。

firefox缓存iframe src时也遇到了同样的问题,禁用原始页面和iframe页面上的缓存也无济于事。我们将以下代码(jQuery代码)放入iframe的onload函数中:

$(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;
      }
    }
});

据报道,这是firefox的一个bug:

一种解决方法是重置iframe的src: document.getElementById('iframe_id')。src='target_url'


仍然会有两个请求:第一个请求是错误的,在第二个请求是正确的之前立即被取消。

所有其他答案在我的情况下都不起作用。因此,我决定解决使用JavaScript动态创建总iFrame的问题,如中所述:


var ifrm=document.createElement(“iframe”);
ifrm.setAttribute(“src”http://localhost/test.php?rand_val=");
ifrm.style.width=“500px”;
ifrm.style.height=“500px”;
document.getElementById(“dynamicload”).appendChild(ifrm);

我已经禁用了服务器端和客户端的缓存,但它不起作用。我看到了视图源,随机id每次都正确生成,iframe src也正确更改,但是$\u请求对象似乎没有更改。嘿,Rajiv,你的解决方案工作得很好。感谢五年前的回复,41.0.2中仍然存在bug(类似?)。。。皮蒂:几乎6年后,如果没有敏感的客户数据,我无法复制它,今天我升级到FF 48。还是个问题-_-这是2019年,我在FF 67开发者版上。Iframe仍然无法为我正确加载。刷新页面后,iframe将变为空白。只发生在FF上。
$(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;
      }
    }
});
<div id="dynamicload"></div>

<script type="text/javascript">
    var ifrm = document.createElement("iframe");
    ifrm.setAttribute("src", "http://localhost/test.php?rand_val=<?php echo $rand_val; ?>");
    ifrm.style.width = "500px";
    ifrm.style.height = "500px";
    document.getElementById("dynamicload").appendChild(ifrm);
</script>