开发者

Getting access to window object in JSM

I am creating a firefox extension. I want to get a reference to the window object in a JSM file.

The file is th开发者_StackOverflow中文版en 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?


To get access to the window object that you want, see this documentation.


Here is some code from my addon, Power Bookmarks:

gBrowser.contentDocument.documentElement.getElementsByTagName("body")[0].innerHTML+="<div id=\"powerbookmarks.div\" style=\"background-color: black; padding-left: 2px; z-index: 9999; opacity: 0.8; width: 100% !important; position: fixed; bottom: 0px; left: 0px; height: 45px !important; color: white !important;\">Content removed to keep it short</div>";

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜