NamePros.Com (http://www.namepros.com/)
-   Programming (http://www.namepros.com/programming/)
-   -   No Cached Image (http://www.namepros.com/programming/452269-no-cached-image.html)

newsiness 04-01-2008 03:22 PM

No Cached Image
 
Everything works fine except that when a new image is uploaded to replace an existing one, the browser still displays the former one until i refresh the page.

By using this piece of PHP, the browser thinks its a new image and reloads.
Code:
<img src="img.jpg?rand=<?=rand(1,1000);?>" />


Anyway to complete the same task in Javascript instead of PHP?

Thanks in advance!!!

SecondVersion 04-01-2008 07:40 PM

Code:
<script language="javascript"> document.write('<img src="img.jpg' + Math.ceil(Math.random() * 10000) + '" />'); </script>

Something like that.

xrvel 04-02-2008 04:35 AM

Its based on Eric's explanation :tu:

Code:
<script type="text/javascript"> function refreshImage(imageId) { var objImage = document.getElementById(imageId); var oldSrc = objImage.src; var cleanSrc = oldSrc.substr(0, oldSrc.indexOf('?')); var newSrc = cleanSrc + "?" + Math.ceil(Math.random() * 10000); //alert(newSrc); objImage.src = newSrc; } </script> <!-- Put at least one ? here --> <img src="yours.jpg?" id="your-image" /> <input type="button" value="refresh" onclick="refreshImage('your-image')" />

newsiness 04-03-2008 03:00 PM

Thanks Guys!!!
Rep Added. :)


All times are GMT -7. The time now is 07:47 PM.
Site Sponsors
Advertise your business at NamePros

Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0