How to use jQuery in Firefox Extension

2019-01-02 19:59发布

I want to use jQuery inside a firefox extension, I imported the library in the xul file like this:

<script type="application/x-javascript" src="chrome://myExtension/content/jquery.js"> </script>

but the $() function is not recognized in the xul file neither do the jQuery().

I googled about the problem and found some solutions but no one did work with me: http://gluei.com/blog/view/using-jquery-inside-your-firefox-extension http://forums.mozillazine.org/viewtopic.php?f=19&t=989465

I've also tried to pass the 'content.document' object(which refrences the 'document' object) as the context parameter to the jQuery function like this:

$('img',content.document);

but still not working, does any one came across this problem before?

7条回答
呛了眼睛熬了心
2楼-- · 2019-01-02 20:44

Instead of

$('img',content.document);

you can try

$('img',window.content.document);

In my case it works.

查看更多
登录 后发表回答