It sounds simple enough, but then there is browser caching that you need to work around. Fortunately, this problem is easy to solve just by altering the URL of the source, adding a unique string to the end (such as a timestamp) as a GET parameter. Here is a little JavaScript function that will accomplish this:
Code: Select all
function reloadImg(id) {
var obj = document.getElementById(id);
var src = obj.src;
var pos = src.indexOf('?');
if (pos >= 0) {
src = src.substr(0, pos);
}
var date = new Date();
obj.src = src + '?v=' + date.getTime();
return false;
}
Code: Select all
<img src="image.jpg" id="img" />
<a href="#" onClick="return reloadImg('img');">Reload Image</a>