2010-11-10 187 views
2

我有一個使用coda-slider在照片之間移動的Firefox擴展。 Coda-slider需要jQuery可用。有沒有辦法在頁面加載後將jQuery包含在頁面的DOM中,以便在插入頁面後加載它?在Firefox擴展中使用jQuery擴展

+1

你問[同樣的問題昨天(http://stackoverflow.com/questions/4137353/jquery-in-firefox-extension)。你有兩個答案。他們沒有工作嗎?如果不是,爲什麼不呢?請不要兩次提問,而是要對提供的答案發表評論。 – 2010-11-11 15:46:21

回答

4

假設你的分機可以使用JavaScript:

這個片斷
var s=document.createElement('script'); 
s.setAttribute('src','https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'); 
// or whatever other url you want to get jQuery from. 
document.getElementsByTagName('body')[0].appendChild(s); 

來源:Learning jQuery

0

您可以使用Firefox的jQuerify插件。它也可用於鉻也但不確定

+0

我讀到這個問題的方式表明OP希望從他正在寫的擴展中包含jQuery; jQuerify可以通過編程方式調用嗎? – 2010-11-15 06:26:28

2

使用下標加載程序組件效果很好。唯一的缺點是你必須包含jQuery作爲本地資源(無論是在Chrome中還是作爲模塊)。例如:

var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"] 
      .getService(Components.interfaces.mozIJSSubScriptLoader); 
loader.loadSubScript("chrome://myext/content/jquery-1.5.2.min.js"); 

https://developer.mozilla.org/en/mozIJSSubScriptLoader