如何强制Chrome在刷新页面之前不重新加载具有相同url的图像,如firefox [英] how to force chrome not to reload images with same url till the page is refreshed ,like firefox

查看:111
本文介绍了如何强制Chrome在刷新页面之前不重新加载具有相同url的图像,如firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Firefox直到刷新后才会使用相同的URL重新加载图像.

Firefox doesnt reload images with the same url till refresh.

$("#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中显示了旧图像,因此除非刷新html页面,否则它不会询问mysql id = 2的图像是否已更改.会显示新的更改过的图像.它会再次询问mysql,不在乎url是否仍然相同.

then i go back to the html page and click #a, in firefox the old image is shown so it doesnt ask mysql if the image with id=2 is changed or not unless the html page is refreshed.But in chrome the new,changed image is shown.it goes and asks mysql again ,doesn't care if the url is still same.

我希望chrome的行为类似于firefox.试图设置expire,lastmodified等标题,以便不进行缓存,但是它以不同的方式工作.据我所知,它不是在缓存我正在寻找的内容.无论如何,这是对我来说,这是一个非常重要的问题,我将不胜感激.

i want chrome to behave like firefox.Tried to set expire,last modified etc. headers for no caching but it worked in a different way.as far as i sensed it is not caching what im looking for.Anyways, this is a really important issue for me i would appreciate any help.

推荐答案

使用它;

<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.您无需在后端php中处理rand

This will always generate different url. You dont needt to handle rand at the backend php

这篇关于如何强制Chrome在刷新页面之前不重新加载具有相同url的图像,如firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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