> <ki********@hotmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi,
I have an Intranet page that has an image that changes each day, but
the image is caching and not updating until the user manually does a
page refresh. I want the page to refresh itself but i dont want to
use
a timed refresh such as every 5 mins etc. I want it so when the user
comes in in the morning and opens the page it will have the updated
image immed.
I'm not sure what the desired goal is, to refresh the page, or to ensure
the image is "fresh", it seems like you want both, but I'll stick to
solving the image "freshness" issue, because it seems to me that is what
the post is about.
I am thinking that JavaScript code to check for a cookie and if it is
not there perform a page refresh. Then write the cookie to the user's
computer that has a life span of 8 hours. That way the cookie should
expire by the next morning as most users leave at 5pm.
I assume the image is changed on the server but named the same? If so,
use the following:
<script type="text/javascript">
var today = new Date();
document.write(
'<img src="yourimagename.jpg?' +
today.getYear() +
today.getMonth() +
today.getDate() +
'" ...>'
);
</script>
It doesn't produce a human readable date, but what it does produce is a
unique value for every day of every year, ensuring that when the page is
reloaded (by whatever means) the URL to the image is different for each
day. Most user agents (Web browsers) will see this different URL as a
completely new resource and insist on loading it from server because
yesterday the user agent cached: "yourimagename.jpg?105319" but today
the user agent is requesting: "yourimagename.jpg?105320", which is does
not have a cached copy of.
If you have server-side processing available (Perl, PHP, ASP, JSP,
ColdFusion, etc), it would be even better to do the unique image URL
there, avoiding any dependancy on client-side JavaScript. Example in
server-side javascript
:
<%
var today = new Date();
today = today.getYear() + today.getMonth() + today.getDate() ;
%>
<img src="yourimagename.jpg?<%= today %>" ...>
--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ -
http://jibbering.com/faq