2015-08-29 64 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

相關問題