3

I'm working on porting a Chrome extension over to Firefox. In the Chrome extension, the background script includes JQuery, which is used for AJAX throughout the background scripts.

With the Firefox Jetpack SDK, it looks like i can do:

require("modulename")

but this only works if modulename is a firefox extension module, including the code:

exports.someVar = someLocalVar

in order to make the module functionality available elsewhere. Obviously JQuery isn't set up as a module like this, so there's no way to require it.

Is there some way to include JQuery in my lib/main.js file in the background of my Firefox addon, such that I get access to JQuery in my main() function?

4

1 回答 1

1

自从发布此消息以来,我已经认识到这是一项徒劳的努力。正如 Wladimir Palant 在评论中指出的那样,JQuery 旨在访问 DOM。由于 main.js 文件没有窗口或文档对象,因此此功能完全没用。

我本来打算将 JQuery 用于 AJAX,它在 Chrome 背景脚本中可以正常工作,但是 Firefox 插件没有 XMLHttpRequest 对象,所以 JQuery 在这里也没什么用。正确的解决方案是改用 firefox Request() API 重写我的代码。

如果您想在 CommonJS 应用程序中包含 JQuery,我发现了这个项目,它将 JQuery 放入一个模块中,假设您定义了窗口、文档和 XMLHttpRequest:https ://github.com/jakobmattsson/commonjs-jquery

于 2012-06-19T13:51:04.593 回答