将Jquery和其他JS库添加到Firefox扩展 [英] Adding Jquery and Other JS libraries to Firefox Extension
问题描述
如何在我的firefox扩展中包含jquery和其他脚本?我知道这个主题是在SO上提出的许多其他问题的副本,但是没有一个问题如此有用.
How do I include jquery and other scripts in my firefox extension? I know this topic is a copy of many other questions asked on SO, but none of them were so helpful.
我尝试在要使用jquery的JS文件之一中使用
I tried using in one of the JS files where i want to use jquery,
Components.utils.import('chrome://myaddon/content/jquery.min.js');
但这给了我一个错误,说
but it gives me an error saying,
ReferenceError: window is not defined
我也尝试将脚本添加到XUL文件中,但是以某种方式,我也无法使其正常工作.
I also tried adding the script in XUL file, but somehow, I cant get it to work as well.
还有其他解决方法吗?
Is there any other way around it?
推荐答案
好的,这是使用自定义事件的解决方案.
Ok man here's the solution to using Custom Events.
非常感谢@ M.J. Saedy弄清楚了这一点.
Much thanks to @M.J. Saedy for figuring this one out.
要点-这里是一个模板,将侦听从非特权范围分发的自定义事件
Gist - HERE is a template that will listen to custom events dispatched from non-privileged scope.
这篇关于将Jquery和其他JS库添加到Firefox扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!