mozilla
Your Search Results

    How To Pass an XPCOM Object to a New Window

    この記事はまだ日本語に翻訳されていません。MDN の翻訳はボランティアによって行われています。是非 MDN に登録し、私たちの力になって下さい。

    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]".

    ドキュメントのタグと貢献者

    Contributors to this page: Nickolay, Sheppy, jswisher, Shaver
    最終更新者: jswisher,