Hi guys,
I want to reload a image using javascript, i know the way to reload the entire document but i only want to reload the image. Does some know how to do this?
Hi guys,
I want to reload a image using javascript, i know the way to reload the entire document but i only want to reload the image. Does some know how to do this?
Try the following code if does what you need:
Code:<script type="text/javascript"> function reloadImage(){ if(document.images){ document.images['imageName'].src = 'Image.jpg?' + Date.parse(new Date().toString()); } setTimeout(reloadImage,5000); } </script> </head> <body onload="reloadImage()"> <img name="imageName" src="Image.jpg">
The animation stops if the user moves around the page with a link like the one at the bottom of this page. Experienced users can force a reload to get the images going again, but the following JavaScript function can be used to ensure they are automatically restarted:
function reloadThePage() {
document.images[0].src=""
document.images[0].src="Dragon_Running.gif"
}
This is called by adding an onClick handler to FORM buttons or A anchor tags like this:
onClick="reloadThePage()"
See this page Javascript Reload Test
If you'll use your using setTimeout() , this will only change the image. You need to change the image and the attached link. You need to use setinterval() instead. And instead of having the setInterval() twice. Just use <body onload="clock()"> you alluded to), it will change the image and the link.
Bookmarks