2012-02-22 69 views
4

我有一個書籤,繼續使用緩存版本http://www.imvu-e.com/products/hpv/download/HPV.js。我希望它永遠不會緩存它,並始終重新加載它。如何強制使用javascript和基本腳本加載緩存

這是我用來保存書籤(其中用戶拖動到其安裝瀏覽器工具欄)的超級鏈接:

<a href="javascript:(function(){ 
    c = document.createElement(&quot;script&quot;); 
    c.type = &quot;text/javascript&quot;; 
    c.src = &quot;http://www.imvu-e.com/products/hpv/download/HPV.js&quot;; 

    c.onload = c.onreadystatechange = function()     { 
      if (! (d = this.readyState) || d == &quot;loaded&quot; || d == &quot;complete&quot;){ 
       document.documentElement.childNodes[0].removeChild(c); 
       version='beta'; 
      } 
    }; 
    document.documentElement.childNodes[0].appendChild(c); 
})();">Run HPV</a> 
+0

js/html ..的混合很糟糕使用一個js框架 – dynamic 2012-02-22 17:32:54

+2

@ yes123這是一個書籤,你應該把一個體面的塊在網址(因爲它需要執行加載你的更復雜的js文件) – wheresrhys 2012-02-22 17:57:04

回答

15

一個無用的查詢字符串添加到您的網址的結尾:

c.src = "http://www.imvu-e.com/products/hpv/download/HPV.js?" + (new Date).getTime(); 
+0

+1,但它應該是日期.getTime() – wheresrhys 2012-02-22 17:57:46

+0

@wheresrhys謝謝,更新。 – Prescott 2012-02-22 18:11:20

+9

必須使用'c.src =「http://www.imvu-e.com/products/hpv/download/HPV.js?」 + new Date()。getTime();' – ParoX 2012-02-22 18:51:54

0

使用jQuery的getScript代替腳本標記和更改源文件

<script> 
    $.getScript("JavascriptFileName.js?timestamp=" + new Date().getTime()); 
</script> 
+3

我正在撰寫SO評論,因爲您的答案已被標記爲其質量。在回答時,請注意您的答案將來可能會被多次閱讀。這使得在他們中寫入解釋性註釋變得很重要。請您花一兩分鐘編輯您的答案,並附上一些文字,說明您的答案如何以及爲何提供瞭解決方案? – 2017-04-18 20:39:49