JavaScript fails to invoke ActiveX interface solution and Usage experience

Source: Internet
Author: User

Some time ago the company did a relatively large project, need to use the OCX control, I plant most of the projects are used C#.net, and the WinForm program bar with the OCX interface is relatively simple, but JavaScript call OCX interface, but and WinForm usage somewhat different, In fact, it can be found that: the difference is not big.

This article mainly elaborated in the project to call the OCX control interface with JavaScript, namely the ActiveX control encountered the problem and the solution. WinForm usage is not described in this article.

Before invoking the ActiveX plugin, we have to do some preparatory work, and we present two scenarios:

1. Using the regsvr32 command to register the OCX control and then working with the Web paging file, let's take the HTML file as an example: Add the following code to the DOM structure:

<ObjectID= "Activexclient"ClassID= "Clsid:e85d67b7-b439-46c0-8f7b-18c06774b4b0"style= "left:0px; width:100%; top:0px; height:1px ">        <paramname= "_extentx"value= "22860">        <paramname= "_extenty"value= "1217">    </Object>

You can then use the object to invoke the ActiveX control's interface, called by: Activexclient.function ();

You can get the interface object directly with the ID.

This method has an inconvenience: every time you open IE browser will prompt:

Click Allow blocked content to have permission to use the control interface. Of course we can reduce the extent of IE interception, but this is not safe. The most important thing is: we can not force users to click this button every time to use our plug-in, not to ask users to reduce their browser security. So we have plan two.

2. Package the OCX control into a cab package, and the packaging method will be searched by yourselves. Finally we get a file with a suffix named Cab.

Also joins a DOM object into the DOM structure of the page, but this time it is different: we need to add a property: CodeBase, the value of this property is the path of the CAB package. For example:

<object id= "cticlient" classid= "clsid:e85d67b7-b439-46c0-8f7b-18c06774b4b0" codebase=http://localhost /download/mycab.cab#version=1,5,7,2 Style= "left:0px; width:100%; top:0px; height:0px ">
<param name= "_extentx" value= "22860" ><param name= "_extenty" value= "1217" ></object>

In the Open this page, IE will directly pop up the prompt box: whether to install the plug-in, 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 trouble of browser permissions, once and for all.

When the CAB package version is updated, the browser automatically installs the latest CAB package and is easy to maintain as long as the file is updated and the version number of the CAB package in the code is changed.

The following author describes the problems encountered in the development process: the page prompts to install the CAB package succeeds, but when I start to tune the interface, I always say 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, the 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, can be the ActiveX plug-in is so stipulated, cannot hide it, so we will display:none removed, the interface finally can be called normally. 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 and other properties to 0 so that it can be called normally without affecting the page layout.

JavaScript fails to invoke ActiveX interface solution and Usage experience

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.