You are here: Reference > JavaScript > client-side > browser > objects > Components

Components object

Browser support:
Implements the XPConnect (Cross Platform Connect) technology that provides interaction between XPCOM (Cross Platform Component Object Model) and JavaScript.
XPCOM is similar to Microsoft COM.

Syntax:

Properties that reference the object:
window.Components

Possible members:

Properties:
classes
Returns a read-only object through which the registered component classes are accessible by ContractID (contract identifier).

This property is read-only.
classesByID
Returns a read-only object through which the registered component classes are accessible by ClassID (class identifier).

This property is read-only.
interfaces
Returns a read-only object through which interfaces are accessible by name.

This property is read-only.
interfacesByID
Returns a read-only object through which interfaces are accessible by IID (interface identifier).

This property is read-only.
lastResult
Returns an integer that represents the result of the most recent XPCOM method call.

This property is read-only.
manager
Returns a reference to the global component manager service.

This property is read/write.
results
Returns a read-only object through which the known result codes are accessible by name.

This property is read-only.
returnCode
Returns an integer that represents the result of the current XPCOM method call.

This property is read/write.
stack
Returns an object that represents the current JavaScript call stack.

This property is read-only.
utils
Implements useful features for the XPConnect (Cross Platform Connect) technology.
Methods:
Constructor (contractID [, interfaceName [, initFuncName]])
Creates a function that can be used to create an instance of the specified XPCOM component.

Parameters:

contractID
Required. String that specifies the contract identifier of the component.
interfaceName
Optional. String that specifies the interface name for the component. If this parameter is specified, the QueryInterface method will be called on each instance during creation with the specified interface name.
initFuncName
Optional. String that specifies the name of the function that needs to be called on each newly-created instance.

Return value:

Returns a function that can be used to create an instance of the specified XPCOM component.
Exception ([ message [, result [, stack [, data]]]])
Creates an XPCOM exception object that provides more complex error handling in JavaScript.
Use the throw statement to throw an exception in JavaScript.

Parameters:

message
Optional. String that specifies the error message for the exception.
result
Optional. Integer that specifies the result code of the exception.
stack
Optional. The XPCOM stack to be set on the exception.
data
Optional. Arbitrary additional data.

Return value:

Returns the created XPCOM exception object.
ID (clsID)
Creates an object that represents an IID (interface identifier).

Parameters:

clsID
Required. String that specifies the interface identifier (the format is '{00000000-0000-0000-0000-000000000000}').

Return value:

Returns an object that represents the specified interface identifier.
isSuccessCode (code)
Returns a Boolean value that indicates whether the specified XPCOM result code is valid or not.

Parameters:

code
Required. Integer that specifies the code to check.

Return value:

Returns a Boolean value that indicates whether the specified XPCOM result code is valid or not.

Example HTML code 1:

This example prints a message to the Error Console. If you need other solutions for dumping messages to console windows in different browsers, please see the page for the dump method.
<head>
    <script type="text/javascript">
        if (window.Components) {
                // UniversalXPConnect privilege is required in Firefox
            try {
                if (window.netscape && netscape.security) { // Firefox
                    netscape.security.PrivilegeManager.enablePrivilege ("UniversalXPConnect");
                }
            }
            catch (e) {
                alert ("UniversalXPConnect privilege is required for this operation!");
                return;
            }

            var console = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService);
            console.logStringMessage("A message for the Error Console.");
        }
        else {
            alert ("Your browser does not support this example!");
        }
    </script>
</head>
Did you find this example helpful? yes no

External links:

User Contributed Comments

Post Content

Post Content