Home  >  Article  >  Web Front-end  >  图片img的src不变让浏览器重新加载实现方法_javascript技巧

图片img的src不变让浏览器重新加载实现方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:39:002823browse

javascript给这个img标签的src属性后面拼接一个 ? 和 javascript对象new Date().getTime()毫秒值做成queryString的样子,就能防止被缓存了

在图片地址src不变的情况下让浏览器重新加载图片
实际上,在src不变时,浏览器直接就去读取缓存了

解决办法
var img_src ='http://www.ilsea.net/images/seagull.jpg?t='+Math.random();
这样给图片地址拼接一个随机数,用js重新给 img 的 src 赋值,okay

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn