Web Tips and Tricks

Reload < img > tag  (Image tag) URL(src=) Without Page Refresh

Do something like :

<script language="javascript">

  document.getElementById('imgTagID').src = 
                                    "url-of-image.jpg?random="+new Date().getTime();
</script

This changes the src attribute and adds a random query string to it, forcing the 
browser to reload the image each time you change it. 
 
To reload the image at every 5 seconds, so do something like: 

<script language="javascript">
 
window.setInterval(function()
{
    document.getElementById('imgTagID').src
                                    "url-of-image.jpg?random="+new Date().getTime();
}, 5000);
 
</script 

No comments:

Post a Comment