First I call the function reloadImage1 when the image was loaded as follow:
<img src="loading.gif" onload="reloadImage1(this,'newphoto.jpg')">
and this is reloadImage1:
function reloadImage1(img,isrc)
{
setTimeout("reloadImage2(img,isrc)",2000);
}
and this is reloadImage2:
function reloadImage2(img,isrc)
{
img.removeAttribute("onload");
img.src = isrc;
}
I got the following error message when executing reloadImage1:
ReferenceError: img is not defined
Try changing
reloadImage1to:Check this demo: http://jsfiddle.net/MrATK/