Thursday, March 04, 2010

Check ActiveX Controls Enabled through JavaScript

Interenet Explorer has activeX controls, which can be controlled by user. Before allowing user to access the application which uses activeX controls it is good to run a check on the users browser requirements.

Standard set of the browser check is easy and pretty common like

  • JavaScript Check
  • Cookie check
  • Adobe Reader Check
  • Windows Media Player Check

But to check whether the user has disabled activeX controls there is no straight forward way (as of i knew...if any body know do let me know).

One more way is to create an AJAX request, and check whether we can create XMLHTTP request. If you disable activeX controls in the Internet Explorer options the XMLHTTP request object created will be empty.

Code snippet

function createRequestObject() {
var xmlhttp;
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e) {
xmlhttp=null;
}
}
if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
xmlhttp=new XMLHttpRequest();
}
return xmlhttp;
}
var activex=createRequestObject();
if(activex==null) {
alert('activex Disable XMLXTTP');
} else {
alert('activex Enable XMLXTTP');
}
I have ran tests on this code and looks good. There one more way to do activeX check, thats is via windows Media player check

Here is the code for that
var minVersion = "11";
var WMP = PluginDetect.isMinVersion('WindowsMediaPlayer', minVersion);
if (WMP == -2) {
alert('activex Disable XMLXTTP');
} else {
alert('activex Enable XMLXTTP');
}
This snippet also works fine, but we may land into trouble when the system doesn't have windows Media player. So the latter one is safe bet.

0 comments: