如何强制chrome不重新加载具有相同URL的图像,直到刷新页面,如firefox

Firefox不会使用相同的URL重新加载图像,直到刷新。

$("#a").click(function(){$("#img").attr("src","http://sofzh.miximages.com/javascript/img.php");});  //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.Tried设置过期,最后修改等标题没有缓存,但它以不同的方式工作。据我所知它不缓存我正在寻找。不管怎样,这是一个非常重要的问题对我来说,我将不胜感激任何帮助。

用这个;

  document.write(randomNumber)> 

这将始终生成不同的URL。 你不需要在后端php处理rand

浏览器行为是个人浏览器所独有的。 有些人将浏览器设置为保存历史记录然后缓存,其他人则没有。

您可以通过设置页面上的标题来鼓励或阻止缓存,如下所示:

http://www.php.net/manual/en/httpresponse.setcachecontrol.php

请注意,本地浏览器设置会覆盖此问题。

此外,通过创建不包含查询字符串的URL,例如:

http://www.mydomain.com/myimage3/与http://www.mydomain.com/image.php?id=3对比

你可能会“更好地”鼓励在浏览器中使用缓存,尽管我不再像往常那样。

(诸如zend和codeigniter之类的框架以更易于部署的格式提供没有查询字符串的url结构)