访问 JSM 中的窗口对象
我正在创建一个 Firefox 扩展。我想获取对 JSM 文件中窗口对象的引用。
然后使用 In my_module.jsm 导入该文件,
Components.utils.import("resource://js/my_module.jsm");
其中有这一行:
var jQenv = window.content.document;
抛出错误“窗口未定义”
如何访问 JSM 文件中的窗口对象?
I am creating a firefox extension. I want to get a reference to the window object in a JSM file.
The file is then imported using
Components.utils.import("resource://js/my_module.jsm");
In my_module.jsm there is this line:
var jQenv = window.content.document;
which throws the error, "window is not defined"
How can I get access to the window object in the JSM file?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要访问所需的窗口对象,请参阅此文档。
To get access to the window object that you want, see this documentation.
这是我的插件 Power Bookmarks 中的一些代码:
这将使您访问当前的 body 元素,并且
gBrowser.contentDocument
可能是窗口,其中.documentElement
是实际文档。您可以在以下位置查看上下文中的代码:https://addons.mozilla。点击 chrome > org/en-US/firefox/files/browse/92549内容>> 帮助
我希望这有
Here is some code from my addon, Power Bookmarks:
That will get you access to the current body element and
gBrowser.contentDocument
might be the window where.documentElement
is the actual document.You can view the code in context at: https://addons.mozilla.org/en-US/firefox/files/browse/92549 by clicking on chrome > content > overlay.js
I hope this helps