3

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?

Alexis
  • 23,545
  • 19
  • 104
  • 143

2 Answers2

5

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

sdwilsh
  • 4,674
  • 1
  • 22
  • 20
  • thank you. I found stuff on how to get alert defined within the jsm. This is what I was looking for to get the window defined within the jsm :) – Alexis Dec 03 '10 at 23:18
  • Well, to be able to do an alert, you could just use nsIPromptService. – sdwilsh Dec 04 '10 at 16:37
-1

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

AJ00200
  • 16,327
  • 7
  • 23
  • 21