简体   繁体   English

在Firefox扩展中使用jQuery扩展

[英]Using jQuery extension in Firefox extension

I have a Firefox extension that uses coda-slider to move between photos. 我有一个Firefox扩展程序,该扩展程序使用coda-slider在照片之间移动。 Coda-slider requires that jQuery be available. Coda-slider要求jQuery可用。 Is there a way to include jQuery, after the page has loaded, in the DOM of the page so that after it is inserted it is loaded? 在页面加载后,是否有一种在页面的DOM中包含jQuery的方法,以便在插入页面后对其进行加载?

Assuming that your extension can use JavaScript: 假设您的扩展程序可以使用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);

Source for this snippet: Learning jQuery . 此代码段的源代码: Learning jQuery

Using the subscript loader component works great. 使用下标加载器组件效果很好。 The only disadvantage is that you have to include jQuery as a local resource (either in chrome or as a module). 唯一的缺点是您必须将jQuery作为本地资源包括(在chrome中或在模块中)。 For example: 例如:

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 https://developer.mozilla.org/en/mozIJSSubScriptLoader

You can use jQuerify plugin for firefox. 您可以将jQuerify插件用于Firefox。 It is also available for chrome also but not sure 它也可用于chrome,但不确定

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM