views:

83

answers:

1

In the Firefox extension I'm writing, I have a variable containing some data that I want to be able to access in both the actual extension and in the preferences pane of the extension. When Firefox is loaded, my extension code initializes the variable with the correct data. But, when I bring up my options dialog (which is contained in another XUL file) and try to use that same variable, the variable hasn't been initialized. Both of my extension XUL files are using the same JavaScript source file, but it looks like both XUL files are initializing new copies of the variable. How can I get that variable to be shared?

Thanks!

+3  A: 

You will want to create a JavaScript code module. All the variables and methods inside of it are shared by all locations that include it.

sdwilsh
I created a JavaScript code module for my code, which seems to be working. However, in some of the code I put in the module, I use the DOMParser. Now that the code is in a module, when I try to use the DOMParser, I get an error in Firefox saying DOMParser is not defined. What do I need to do so that I can use DOMParser?
Scott
OK, I figured it out. Instead of just saying var parser = new DOMParser(), I need to use var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] .createInstance(Components.interfaces.nsIDOMParser)
Scott