如何强制chrome不重新加载图像与相同的url,直到页面刷新,像firefox
how to force chrome not to reload images with same url till the page is refreshed ,like firefox
Firefox在刷新之前不会重新加载具有相同url的图片。
$("#a").click(function(){$("#img").attr("src","img.php?id=3");});
<img id="img" src="img.php?id=3">
//the two line above are in the same html page.And when the html page is loaded
// in the browser, i open a new tab and go to the php page that includes
//the line below.
mysql_query("update images set data=$data where id=3");//changing the image here
然后我回到HTML页面并单击#a,在firefox中显示旧图像,因此它不会询问mysql是否更改了id=2的图像,除非HTML页面刷新。但是在chrome中显示的是新的、改变过的图像。它会再次询问mysql,不关心url是否仍然相同。
我希望chrome的行为像firefox。尝试为不缓存设置过期,最后修改等头,但它以不同的方式工作。据我所知,它没有缓存我要找的东西。无论如何,这对我来说是一个非常重要的问题,我将感谢任何帮助。
使用这个;
<script>
var randomNumber = Math.random();
$("#a").click(function(){$("#img").attr("src","img.php?id=3&rand=" + randomNumber);});
</script>
<img id="img" src="img.php?id=3&rand="<script>document.write(randomNumber)</script>>
这将总是生成不同的url。你不需要在后端处理rand
php
浏览器行为因人而异。有些人将浏览器设置为保存历史记录并缓存,有些人则没有。
您可以通过设置页面标题来鼓励或阻止缓存,如下所示:
http://www.php.net/manual/en/httpresponse.setcachecontrol.php注意,这将被本地浏览器设置覆盖。
另外,通过创建一个不包含查询字符串的url,例如:
http://www.mydomain.com/myimage3/vs. http://www.mydomain.com/image.php?id=3
你"可能"有更好的运气鼓励在浏览器中缓存,虽然我不再是这样的情况下,因为它曾经是。
(像zend和codeigniter这样的框架以更容易部署的格式提供不带查询字符串的url结构)
相关文章:
- createObjectURL blob url在Firefox中不安全
- 如何在地址栏中的URL更改Firefox JPM时获得通知
- 无法'共享'Firefox操作系统上Facebook和Twitter本地应用程序上的URL
- Firefox扩展不适用于http://https://以外的URL
- 在Firefox Addon中获取当前浏览器url
- 如何正确创建带有“Url.Action”的查询字符串的网址,以便它在Firefox中工作
- FireFox 无法在 URL.revokeObjectURL 上正常工作
- 如何通过JavaScript访问Firefox内部URL
- Firefox 插件中的 OnBeforeRequest URL 重定向(从 Chrome 扩展程序转换)
- onDrop 事件转发到 url,但仅在 FireFox 中
- AngularJS Firefox encoded URL
- window.open(url,windowname,opts)在新选项卡中打开,而不是在Firefox中打开新窗口
- 在 Firefox 上,window.open(url) 和 window.location.href = url 有什
- 重新访问-在Firefox中加载顶级页面之前修改URL
- URL.用于音频blob的createObjectURL在Firefox中给出TypeError
- 如何在firefox中使用javascript为url添加字段值
- Firefox插件拦截和修改POST数据并获取URL
- Firefox将输入字段中删除的文本作为url加载
- Firefox 在 Docker 中打开 Karma Server URL 后挂起
- facebook如何在Chrome中重写url &Firefox