2015-08-29 62 views
0

我一直想弄清楚如何重新设置内部javascript的gif图像, 之前,我只是添加<?php echo date("Ymdgis");?>尾随在php模板内的内联脚本工作的图像。可能在浏览器中重置.gif img src?

我试图刷新图像http://website/wp-content/themes/file/images/splash1.gif 每次浏览器刷新。

var splash = new Image(); 
splash.src = "http://website/wp-content/themes/file/images/splash1.gif"; 
splash.onload = function() { 
    document.getElementById('here').src = splash.src; 
} 

该函数会将.gif图像附加到我的html中的#here元素中。 谢谢。

回答

1

如果你每天像在浏览器中加载时间更改查询参数,然后在浏览器将不会在高速缓存中的URL,因此将作出新的从服务器请求:

var splash = new Image(); 
splash.src = "http://website/wp-content/themes/file/images/splash1.gif?" + Date.now(); 
splash.onload = function() { 
    document.getElementById('here').src = splash.src; 
} 
+0

好极了!你摇滚! – DarcyHalo

相关问题