How To Pass an XPCOM Object to a New Window

A more useful example is available in the source code: toolkit/components/help/content/contextHelp.js#61

If you want to be able to call functions within an XPCOM object from a XUL window's code, you can do so if you pass the XPCOM object as one of the arguments to the window creation method.

For example:

var ww = 

var win = ww.openWindow(null,
      "debug history", "chrome,centerscreen,resizable", myObject);

Note in this example that myObject is passed to the openWindow() method; you can pass any XPCOM object (or any other value, for that matter) in this way. To access the XPCOM object from the window's code, you can access the window.arguments[] array, as shown in the example below:


This will produce output similar to "[xpconnect wrapped nsIMyXPCOMObject]".

Document Tags and Contributors

 Contributors to this page: teoli, jswisher, Nickolay, Shaver, Sheppy
 Last updated by: jswisher,