问题
I have an image in my app (android) taken from an URL:
<img src="URL"/>
If i change the image on the server (keeping the same URL), the app does not refresh and keeps always the old image.
How can i force the app to reload/refresh the right image (always on the same URL)?
(the app is written with jquery)
回答1:
Try appending a querystring to the image url with a random number that you change each time you display the image.
This may for example be done with javascript.
<img id="myImage" src="URL"/>
<script>
var newRandomNumber = (new Date()).valueOf();
var img = document.getElementById('myImage');
img.src += "?random=" + newRandomNumber;
</script>
This script will get the html element with the id myImage and append a querystring parameter which will (hopefully) force a reload of the image.
(NB the value (new Date()).valueOf() in the code is not random but a number that represents the current time)
Hope this helps!
来源:https://stackoverflow.com/questions/14231872/force-app-to-refresh-image-from-url