Reloading Image in JavaScript
We have displayed an image and now we want to reload the image part only. Check that we are not reloading the full page, we are only reloading the image.
Why reloading is required.
In our captcha generation script , some time user may need another text inside image to be generated.
Let us start with the image display part. Simple one is here .
<img src=captcha-demo.php id="capt">
<input type=button onClick=reload(); value='Reload image'>
Now you can see we have connected onClick button event to a function reload(). The code or reload function is here.
<script type="text/javascript">
function reload()
{
img = document.getElementById("capt");
img.src="captcha-demo.php?rand_number=" + Math.random();
}
</script>
While reloading the image we have added math random number to prevent retrieving the image by browser form cache.
This article is written by plus2net.com team.
plus2net.com
|