How Do I Script an ActiveX Control on a Web Page?
| Overview | How Do I | FAQ | Details | Sample
An easy way to get started with scripting is by using an HTML authoring tool like Microsoft ActiveX Control Pad. This topic shows how to use ActiveX Control Pad to script CIRC3, a control sample used in the tutorials.
The ActiveX Control Pad is an authoring tool that lets you add ActiveX controls and scripting (such as JavaScript and VB Script) to your HTML pages with point-and-click ease. The ActiveX Control Pad also includes the new Microsoft HTML Layout Control, which supports windowless controls and provides new layout capabilities based on the HTML extensions proposed by the World Wide Web Consortium (W3C).
To install and run ActiveX Control Pad
- The ActiveX Control Pad is freely available for downloading from the authoring tools section in the Microsoft Site Builder Workshop, accessible through www.microsoft.com. Follow the online instructions for installation.
To insert Circ3
Start ActiveX Control Pad. It opens with a default HTML document including head and body tags.
On the Edit menu, click Insert ActiveX Control.
In the Insert ActiveX Control dialog box, click the Circ3 control to add it to the page.
The control will be displayed in the Edit ActiveX Control window. You should see a rectangular control containing Circ31. Its properties can be set by changing values in the Properties window.
Close the Edit ActiveX Control window.
The OBJECT tag will be displayed on your HTML page, including the control’s class ID and other parameters used to instantiate the control at run time.
Now you are ready to script the control.
To use VBScript to invoke properties and methods on Circ3
Start ActiveX Control Pad and open the file created in the previous procedure containing a Circ3 control, if it is not already open.
On the Tools menu, click Options, and then click Script.
In the Script Options dialog box, select Visual Basic Scripting Edition as the Default Script Language and click OK.
From the Tools menu, click ScriptWizard.
The following steps are all performed in the Script Wizard dialog box
In the Select an Event list, click Window, and then click Load to add code to run when the control is loaded.
In the Insert Actions list, click AboutBox, and click Insert Action. The following code to invoke the AboutBox method is inserted into the HTML file:
<SCRIPT LANGUAGE="VBScript"> <!-- Sub window_onLoad() call Circ31.AboutBox() end sub -->
To use JavaScript to invoke properties and methods on Circ3
Start ActiveX Control Pad and open the file created in the previous procedure containing a Circ3 control, if it is not already open.
On the Tools menu, click Options, and then click Script.
In the Script Options dialog box, select JavaScript as the Default Script Language and click OK.
From the Tools menu, click ScriptWizard.
The following steps are all performed in the Script Wizard dialog box.
In the Select an Event list, click Window, and then click Load to add code to run when the control is loaded.
In the Insert Actions list, click AboutBox, and click Insert Action. The following code to invoke the AboutBox method is inserted into the HTML file:
<SCRIPT LANGUAGE="JavaScript" FOR="window" EVENT="onLoad()">
<!--
Circ31.AboutBox()
-->
Save the file and open it in a Browser. You should see the AboutBox displayed.
You can see how simple it is to add a control to a Web page using an authoring tool, and to use scripting to invoke its properties and methods. You can easily attach JavaScript or VBScript code to buttons on your HTML pages.