Content on this page
Introduction
Compile ActiveX Controls
Access ActiveX control using JavaScript
Access ActiveX Control Using VBScript
Description
Introduction
Now we use VB to create an axtivex control and then call it on the web. This may be because of the old technology. There is very little information, and ActiveX functions are still very powerful. I would like to sum up some experiences. It is about accessing properties, methods, and events of ActiveX controls using JavaScript and VBScript.
Compile ActiveX Controls
As an example, the simplest ActiveX control is compiled here, which only includes one attribute, one method, and one event. The procedure is as follows:
1. Open VB6, create an ActiveX Control Project, and drag and drop two command controls on the design interface,
2. Write the following code in the Code view:
Public myvalue as string Public event testevent () Private sub commandementclick () Msgbox me. myvalue End sub Private sub command2_click () Raiseevent testevent End sub Public sub invokemethod (byval par as string) Msgbox "invokemethod, the parameter is:" & par End sub |
3. Then Package the ActiveX control.
Access ActiveX control using JavaScript
<Script language = "JavaScript" id = "Mian">
// Attributes
Function go ()
{
Usercontrol1.myvalue = "Get my value test! ";
}
Go ();
</SCRIPT>
// Event
<SCRIPT id = "clienteventhandlersjs" Language = "JavaScript" for = "usercontrol1" event = "testevent">
Window. Alert ("Raise event test! ")
</SCRIPT>
// Method
<SCRIPT id = "eventforbutton1" Language = "JavaScript" for = "button1" event = "onclick">
Usercontrol1.invokemethod ("Java parameter ");
</SCRIPT>
Access ActiveX Control Using VBScript
<Script language = "VBScript">
'Attribute
Usercontrol1.myvalue = "Get my value test! "
'Event
Sub usercontrolpolictestevent ()
Msgbox "Raise event test! "
End sub
'Method
Sub button1_onclick ()
Usercontrol1.invokemethod ("VB parameter ")
End sub
</SCRIPT>
Description
Note that if you write the script code before the ActiveX control, ie loads the entire page and runs the script file first. In this case, the ActiveX object does not exist, the solution is to write the script after the ActiveX declaration.