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 usingComponents.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
精彩评论