Access ActiveX controls using JavaScript and VBScript on the Web

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.