Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

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 = 
      Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
            getService(Components.interfaces.nsIWindowWatcher);

var win = ww.openWindow(null,
      "chrome://myextension/content/debug.xul",
      "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:

Components.utils.reportError(String(window.arguments[0]));

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,