Now I am developing a firefox extension, can I define a global array in a js with the main xul . and I found when I use it in another js with another xul , it could not worked , so I searched the document of Firefox development. I found a common array can not be transfered between two js files with different xul files. and then I defined a xpcom mutablearray in a js:

1 Answer
1

The problem is that even when you create the mutable array, you are storing the reference to this array object in a variable in the context of the XUL that creates it. From the other XUL, you don't see that variable so you cannot access the array.

There are several solutions to access an object accross different contexts:

From one of the contexts, get a reference to the other context. For example, you have a variable defined in the main window (browser.xul overlay), you can get it from a sidebar by using the window manager to get a reference to the main window.

You can create your own XPCOM object, although this is not simple to do, specially for a simple case like yours

You can used JavaScript modules to create a global singleton.

You should consider looking into the JavaScript modules option. It's the easiest and most reliable way. It was introduced in Firefox 3.0 and you can do it using only JavaScript without having to create a XPCOM

Firstly thank you very much! and as you said:"you have a variable defined in the main window (browser.xul overlay), you can get it from a sidebar by using the window manager to get a reference to the main window." I didn't know it clearly. and my case just same you have said:I get a array of observing swf files path in a js of main window(browser xul overlay),and I want to get them from a sidebar js, so I would to defined a variable in browser.xul? and how to do , how to get it from a sidebar js? Thank you again.
–
jinJun 7 '10 at 2:21

Just added some more information to the response. Hope it helps!
–
flpmorJun 7 '10 at 13:06

Thank you for your help , I think these code maybe add in js of xul,because my js code is long?
–
jinJun 8 '10 at 1:34