大网数据广告活动
Windows 系统接口

Embedding COM Objects in Web Pages

· 52CE 我爱测

You can use COM objects in webpages. To do this, first create an instance of that COM object. After an object instance is created, you can use it in subsequent scripts on that webpage.

You can use COM objects in webpages. To do this, first create an instance of that COM object. After an object instance is created, you can use it in subsequent scripts on that webpage.

To create a COM object instance in a webpage, 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 webpages 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 webpage:

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

After 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>
 

If you are writing scripts embedded in a webpage, the browser also exposes an object model that your scripts can access. The model used by Internet Explorer conforms to the Document Object Model (DOM) proposed by the World Wide Web Consortium (W3C).

Related topics

Scripting with COM Objects

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。