Use JavaScript to determine whether the browser has installed ActiveX controls and whether to prohibit the running of ActiveX Controls

Source: Internet
Author: User

After Microsoft assigned SP2 to IE, when ie opened some web pages containing ActiveX controls, a prompt box is displayed, asking the user to choose whether to install the control; by default, common users do not know what is going on. The company's products also encountered such problems. The only way is to make the control into an EXE file for users to download and manually install and register. In this way, a test is required, if the user does not install the control, the system prompts the user to download and install the control. If the control is installed, the system directly goes to the relevant page. I tried a lot of methods and finally found a reasonable solution. Because of the Ajax technology that we often use today, it is actually a COM component. To send requests and obtain data through interfaces, we must create such a COM component to use Ajax, so we can start from here to solve the problem of checking whether common controls are intercepted.

You can create ActiveX controls using JavaScript as follows:

Function detectactivex ()
{
Try
{
VaR comactivex = new activexobject (Control name);
}
Catch (E)
{
Return false;
}
Return true;
}

As long as the control has been installed, the creation will succeed (if IE is set to disable ActiveX, it will fail). If the control is not installed, it will fail. This is a simple detection method. How can I know the control name? When you write a COM component, there is a correspondingCLSID. Open your registry (the control has been installed in your system ),Hkey_classess_rootAnd enter the correspondingCLSIDIn the directory namedCLSIDFind the registration information of the corresponding control in the directory of, open the node, one of which isProgidThe corresponding value is the name used to create the control, so that you can easily create and detect the control you designed.

Because IE does not allow JavaScript to access system functions, we cannot directly access the relevant settings of IE, so we can try it based on the above detection, we can easily determine whether IE is prohibited from running ActiveX controls. This is also very useful because many prompts may prompt users for any reason, as a result, the function of an ActiveX control cannot be used. So how can we make judgments? Remember the Ajax thing I mentioned at the beginning. It not only brings better user interaction functions, it can also be used to check whether the browser is prohibited from running ActiveX controls. Because Ajax is supported by the relevant COM components, whether it is IE, Firefox, Netscape, opera and other browsers, there are corresponding implementations, because it is the browser standard. Therefore, we only need to write a common XMLHTTP object that can be used by various browsers to Create Ajax. If it can be successfully created, it proves that IE is all OK. If it fails, a prompt is given, I believe that the detection function is no longer familiar to everyone, but our current goal is different.

Function disactivex ()
{
// XMLHTTP Object
VaR kxmlhttp = NULL;
Try
{
// Non-Microsoft IE Supported XMLHTTP Object
If (typeof XMLHttpRequest! = "Undefined ")
{
Kxmlhttp = new XMLHttpRequest ();
Return true;
}
}
Catch (E)
{}
// Microsoft IE Supported XMLHTTP Object
VaR aversionhs = ["msxml2.xmlhttp. 5.0 ",
"Msxml2.xmlhttp. 4.0 ",
"Msxml2.xmlhttp. 3.0 ",
"Msxml2.xmlhttp ",
"Microsoft. XMLHTTP"];
// IE Creation Method
For (VAR I = 0; I <aversionhs. length; I ++)
{
Try
{
Kxmlhttp = new activexobject (aversionhs [I]);
Return true;
}
Catch (E)
{}
}
Return false;
}

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.