force app to refresh image (from URL)

假如想象 提交于 2019-12-11 17:50:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!