iframe重新加载缓存问题 [英] iframe reload caching issue

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

问题描述

我在iFrame中执行以下代码:

I am executing the following code in an iFrame:

window.frames[0].location.reload();

重新加载页面,然而,看起来像 SOMETIMES 数据是缓存。我找到了它正在重新加载的URL的来源。我想做的是在URL上附加一个随机数,这样当它重新加载时它是唯一的并且会阻止缓存。

It reloads the page, however, it looks like SOMETIMES the data is cached. I found the source of the URL that it is reloading. What I would like to do is append a random number to the URL so that when it reloads it is unique and will prevent caching.

我怎么能用上面这个码?

How would I do that with the above code?

更新:

我修改了我正在尝试的代码将href设置为我构建的新URL字符串。但是,看起来当我在设置它之后打印出location.href(上面一行)时,我仍然得到旧的location.href。

I have modified the code where I'm attempting to set the href to a new URL string that I built. However, it looks like when I print out the location.href after setting it (the line above), I'm still getting the old location.href.

            window.frames[0].location.href = newIfURL;
            console.log(window.frames[0].location.href);
            window.frames[0].location.href();

我这样做了吗?

推荐答案

类似于:

var fl = window.frames[0].location;
var href = fl.protocol + '//' + fl.host + fl.pathname + '?random=' + Math.random() + fl.hash;
window.frames[0].location.href = href;

当然,如果你需要保留搜索参数,那么你需要添加一些逻辑确定如何添加随机参数。

Of course, if you need to preserve "search" parameters, then you will need to add some logic to determine how to add the random parameter.

这篇关于iframe重新加载缓存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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