Some time ago the company made a relatively large project, need to use OCX control, I plant most of the projects are used C#.net, and WinForm program with OCX control interface is relatively simple, but the JavaScript call OCX interface, but and WinForm use a little different, In fact, it can be found that: the difference is not big.
The author of this article mainly describes the use of JavaScript in the project to invoke OCX control interface, that is, ActiveX controls encountered problems and their solutions. WinForm usage is not described in this article.
Before invoking the ActiveX plug-in, we need to do some preparatory work, and we'll introduce two scenarios:
1. Use the regsvr32 command to register the OCX control, and then use the processing Web page file as an example of an HTML file: Add the following code to the DOM structure:
You can then use the object to invoke the interface of the ActiveX control, calling the method: Activexclient.function ();
You can get the interface object directly with an ID.
This method has a disadvantage: every time you open IE browser will be prompted:
Click Allow blocked content to have permission to use the control interface. Of course we can reduce the degree of IE interception, but this is not safe. The most important thing is: we can not force users to click the button every time to use our plug-ins, but also can not ask users to reduce their browser security. So we have plan two.
2. The OCX control package as a cab package, packaging methods for everyone to search, here do not repeat. Finally we get a file with a suffix named Cab.
Also add a DOM object to the page's DOM structure, but this time it is different: we need to add a property: CodeBase, the value of this property is the path to the CAB package. For example:
When you open the page, ie pops the prompt box directly: Whether you want to install the plugin, select Yes. After the installation is complete, the system will automatically register the OCX control, and let the browser call itself, no longer have the browser rights of worry, once and for all.
When the CAB package version is updated, whenever the file is updated and the version number of the CAB package in the code is changed, the browser automatically installs the latest CAB package and is easy to maintain.
The following author describes the problems encountered in the development process: page prompts the installation of the CAB package succeeded, but I started to tune the interface, always said that my interface is invalid or does not exist. But the IDE can help me get to the interface, and the interface name and parameters are consistent with the document, which really bothered me for a long time.
Finally, a DOM object added to the DOM structure, whose display property is set to None, is hidden. As we all know, although hidden, but the DOM object is still there, the ActiveX plug-in is so specified, can not hide it, so we will display:none removed, the interface can finally be normal call. To keep it from affecting the style of the page, we can place it at the top or bottom of the page and set its Height property to 0 so that it can be invoked normally without affecting the layout of the page.