在firefox上iframe src缓存问题 [英] Iframe src caching issue on firefox

查看:152
本文介绍了在firefox上iframe src缓存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an iframe element with a random scr attribute. When I do refresh the page every time, the iframe should load the page with different query parameters based on the src attribute. But in firefox, if I try to load dynamic URL in an iframe, it always execute the first time executed URL eventhough the src attribute changes dynamically. The query parameters also not passing correctly. So, how I can solve this issue?

例如:

<?php

$url = "http://localhost/test.php";

$rand_val = rand(1000, 9999);

echo "<iframe name='dynamicload' src='{$url}?rand_val={$rand_val}'></iframe>";

?>


推荐答案

我们遇到了与firefox缓存iframe src相同的问题并禁用原始页面上的缓存以及iframe页面没有帮助。我们将以下代码(jQuery代码)放在iframe的onload函数中:

We had the same problem with firefox caching the iframe src and disabling the cache on the original page as well as the iframe page did not help. We put the following code (jQuery code) in the onload function of iframe:

$(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上iframe src缓存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆