Cross-Browser Check for ActiveX in JavaScript

Once you created an ActiveX control, you need to embed it in your web page.

This is typically done by creating a new ActiveXObject(“myActiveX”), an object type which is only available in Internet Explorer.

To find out whether this object type is implemented, I try to create it, and check the exception name: Firefox has “ReferenceError”, whereas IE returns “Error”. This information is stored in the variable isActiveXCapable.

Next, we create the ActiveX using its registered class name.

Depending on whether the object can be created and, if not, on the result of the first test, we can distinguish the 3 cases:

  • Browser does not support ActiveX
  • Browser supports ActiveX, but the requested class is not installed
  • Browser supports ActiveX, and an object has been created
<script type="text/javascript">
var myActiveX = null;
var isActiveXCapable = false;

function InitMyActiveX() {
  try {
    new ActiveXObject("");
  catch (e) {
    // FF has ReferenceError here
    if ( == 'TypeError' || == 'Error') {
      isActiveXCapable = true;
  try {
    myActiveX = new ActiveXObject("My.ActiveX");
  catch (e) {
    myActiveX = null;

  if (myActiveX != null) {
    document.getElementById("myInfo").innerHTML = myActiveX.GetSomeInfo();
  } else {
    document.getElementById("CallMyActiveX").setAttribute("disabled", "disabled");

    if (!isActiveXCapable) {
      document.getElementById("myInfo").innerHTML = "Browser does not support ActiveX";
    } else {
      document.getElementById("myInfo").innerHTML = "MyActiveX is not installed";

function DoSomething() {
  if (myActiveX != null) {
    var s = myActiveX.DoSomething();
    document.getElementById("myResult").innerHTML = s;

<div id="myInfo"></div>
<input type="button" id="CallMyActiveX" value="Call me" onclick="DoSomething()"  />
<div id="myResult"></div>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: