By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

automatic image reload?

P: n/a
JR
Is there a script available to automatically reload images on visiting
a page? I change images once a week and they have the same name so
I'm not changing the page code. Some people have the previous week's
image in their cache. I'd rather not put a message line on the page
asking the visitor to hit the refresh button nor use a code that
reloads the whole page unless reloding the page is an only option.

Thanks for your suggestions,

John
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Lee
JR said:

Is there a script available to automatically reload images on visiting
a page? I change images once a week and they have the same name so
I'm not changing the page code. Some people have the previous week's
image in their cache. I'd rather not put a message line on the page
asking the visitor to hit the refresh button nor use a code that
reloads the whole page unless reloding the page is an only option.


Append a unique "search" suffix to the src of each image.
You could do this as the page loads, but it's simpler to
do it after the load, as in this example:
<html>
<head>
<script type="text/javascript">
function refreshImages(){
var search="?"+(new Date()).getTime();
for(var i=0;i<document.images.length;document.images[i++].src+=search);
}
</script>
</head>
<body onload="refreshImages()">
<img src="http://www.azphx.com/dhtml/tmp/alpha6464.jpg">
<img src="http://www.azphx.com/dhtml/tmp/beta6464.jpg">
</body>
</html>

Jul 20 '05 #2

P: n/a
JR wrote:
Is there a script available to automatically reload images on visiting
a page? I change images once a week and they have the same name so
I'm not changing the page code.


Client-side JavaScript will not help you in general here: It can be
restricted, disabled or not even supported. You can define that
standards-compliant UAs should always re-download the document and its
linked resources from the original source (that should also exclude the
cache of proxy servers, you did not think about that):

<head>
...
<meta http-equiv="expires" content="0">
...
</head>

On the Web (using HTTP,) you can use the `Expires' HTTP header the same way.
See RFC 2616 for details.

Another way are cookies that store the date of last visit and if that was
more than a week ago, you force to reload with `location.reload(true)'. But
their storage may be seen as a violation of privacy.
PointedEars

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.