NameSilo

No Cached Image

SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
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
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Search: choose where to search from the All tab
Open the search at the top of any page. On the All tab, the list next to the search box lets you choose where to search: everything, all...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back