Sunday, November 16, 2008

Force reload an image using javascript

When we try to reload the image using JavaScript it does not work due to the browser caching the image.

The workaround for this is to append a "#" at the end of the image path ie say the image is
<img src="http://www.blogger.com/captcha.php" id="captcha" /><a href="javascript://document.getElementById().src+='#'">Reload</a>

This way we fool the browser to think its a different image and the browser reloads the image. Simple eh?

1 comments:

Anonymous said...

perfect I like it.

Post a Comment

Web Hosting Cheap PHP Plans Also at For free flags of the world