Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

No Cached Image

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

newsiness

VIP Member
Impact
49
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!!!
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Code:
<script language="javascript">
document.write('<img src="img.jpg' + Math.ceil(Math.random() * 10000) + '" />');
</script>
Something like that.
 
1
•••
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')" />
 
1
•••
Thanks Guys!!!
Rep Added. :)
 
0
•••
CatchedCatched

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back