Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

No Cached Image

SpaceshipSpaceship
NamecheapNamecheap
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
Close
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
Close
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
Close
Thanks Guys!!!
Rep Added. :)
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back