ActiveX Object is not defined

Hristo picture Hristo · Jun 23, 2010 · Viewed 21.4k times · Source

Firebug is giving me the following error:

ActiveXObject is not defined
[Break on this error] var xmlhttp = new ActiveXObject("MSXML2.XmlHttp"); 

I've read that ActiveX is a Microsoft framework and its mostly used in IE. All of the internal web pages at the place I work were designed and built specifically for IE 6, but now they want me to research what it would take to move to Firefox and Safari and other major browsers... and ActiveX does not work in Firefox.

So how do I get the ActiveX stuff to work in Firefox and Safari specifically on Mac (for starters)? I know there is a couple of plugins? that have made things easier... like FF ActiveX Host... but is there a programmatic solution to this?

If there is no solution, no plugin, for this problem, is it possible to rewrite the ActiveX pieces in Java?

Answer

Eugene picture Eugene · Jun 24, 2010

I’m not a web guy but it seems like your web pages use AJAX.

So your problem is not using AcitveX in other browsers.

Try something like this:

var xmlhttp;
if (window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();
} else {
  try { 
    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try { 
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e) {
      xmlhttp = false; 
    }
  }
}