表示中の画像を自動更新、a hrefの画像も最新画像で表示させたい(JavaScript)

Word PressJavaScript

キャッシュに存在する画像を使用させないで、表示中の画像を最新画像に更新させたい。
a hrefの画像も最新画像で表示させたいとき。

<script type="text/javascript">
    function reloadimg(){
				var timestamp = new Date().getTime();
				document.image.src = "sample1.png?" + timestamp; 
				document.links.hrefimg.href = "sample2.png?" + timestamp; 
    }
    function setreload(timer){ 
        setTimeout('reloadimg()',timer); 
    }
</script>

<a name="hrefimg" href="sample2.png">
<img name="image" src="sample1.png" onload="setreload(1000)" onerror="setreload(1000)">
</a>

ファイル名の末尾にパラメータを付与することで、別ファイルとしてサーバに認識させます。