Platform SDK: COM |
You can use COM objects in Web pages. To do this, first create an instance of that COM object. Once an object instance is created, you can use it in the following scripts on that Web page.
To create an COM object instance in a Web page, you can use an OBJECT tag. Alternatively, if your scripting language provides a native way to create COM objects, you can create an object instance using script.
Note that embedding COM objects in Web pages only works with browsers that support ActiveX and COM, for example Internet Explorer.
The following example illustrates using the OBJECT tag to embed a COM object in a Web page:
<OBJECT ID = vid CLASSID = "clsid:31263EC0-2957-11CF-A1E5-00AA9EC79700" BORDER = 0 VSPACE = 0 HSPACE = 0 ALIGN = TOP HEIGHT = 100% WIDTH = 100% > </OBJECT>
You can also create a COM object instance in script, if your scripting language provides a way to create COM objects. For example, VBScript provides the CreateObject method and JScript provides the ActiveXObject object. Creating objects in script is illustrated in the following examples.
<SCRIPT LANGUAGE = "VBScript"> Dim objXL Set objXL = CreateObject("Excel.Application") </SCRIPT> <SCRIPT LANGUAGE = "JScript"> var objXL = new ActiveXObject("Excel.Application"); </SCRIPT>
In addition to the CreateObject method and the ActiveXObject object, both VBScript and JScript provide the method GetObject, which returns an object instance. For more information about GetObject, see the reference documentation for your scripting language.
Once a COM object has been created, you can reference it in subsequent scripts by using the identifier specified in the OBJECT tag's ID attribute. In the preceding example, this identifier was specified as "vid." Note that the script that uses the COM object must appear after the OBJECT tag or script that creates the object instance; otherwise, the object identifier is undefined. The following script uses the objXL object to display the version information for Microsoft® Excel.
<SCRIPT LANGUAGE = "VBScript"> Msgbox objXL.Version </SCRIPT>
For more information about the OBJECT and SCRIPT tags and how to use them, consult an HTML reference, such as the HTML Reference available in the MSDN library.
If you are writing scripts embedded in a Web page, the browser also exposes an object model that your scripts can access. Internet Explorer and Netscape Navigator use similar object models. The model used by Internet Explorer conforms to the Document Object Model (DOM) proposed by the World Wide Web Consortium (W3C). In the future, the Netscape Navigator object model will also conform to this standard.
For more information about the objects, methods, events, and properties provided by Internet Explorer, see the Internet Client SDK section of the Platform SDK.
Note Netscape Navigator does not currently support ActiveX technologies and the OBJECT tag. If your script needs to work in Netscape Navigator, it should not rely on COM objects.