0

I want an internal website to refresh itself ONCE when loaded. The reason is that there are images that are updated, but have the same name. So when I open the website, the old image is shown (from the cache I guess).

The answers I found either didn't work or I didn't know how to implement them, so I'm looking for the simplest answer possible!

This didn't work: (or, weirdly worked a couple of times but not anymore?!)

<html>
<head>
  <meta http-equiv="content-type"
 content="text/html; charset=ISO-8859-1">
  <script language=" JavaScript"><!--
function MyReload()
{
window.location.reload();
}
//--></script>
  <title>TITLE</title>
</head>
<body ...
...
<hr style="width: 100%; height: 1px;"><img
 style="width: 2120px; height: 1171px;" alt="SFD"
 src="image.jpg"><br>
</body>
</html>
Community
  • 1
  • 1
  • Why not just disable caching so the page won't need to be refreshed? See: http://stackoverflow.com/questions/1341089/using-meta-tags-to-turn-off-caching-in-all-browsers for details. – Scott Marcus Feb 17 '16 at 16:05

1 Answers1

0

The first comment is correct, just disable page caching entirely, but if for some reason you don't want to or can't, you can always…

add ? and a timestamp to the end of the image source.

Change your image tag to add a class or ID

<img id="pic" style="width: 2120px; height: 1171px;" alt="SFD" src="image.jpg">

and with this script you can add the timestamp to the end of the image src.

<script>
var timestamp = new Date().getTime();
var image=document.getElementById("pic");
image.src=image.src + "?" + timestamp
</script>
jkuhns5
  • 96
  • 12