19

How do I detect if ActiveX is enabled in the browser of client?

I tried following code, but it's not working in Firefox.

window.ActiveXObject not working in Firefox

any ideas?

check the example here: http://jsfiddle.net/qXSvQ/2/

I get false when I run this example.

Singleton
  • 3,701
  • 3
  • 24
  • 37

4 Answers4

26

ActiveX objects do not exist in anything but Internet Explorer. If you're trying to use them for XMLHTTPRequests, use the XMLHTTPRequest() object instead, using feature detection.

if ("ActiveXObject" in window) { /* Do ActiveX Stuff */ }
else { /* ActiveX doesnt exist, use something else */ }
Philip
  • 769
  • 7
  • 20
9

What isn't working? Is that throwing an error in FF? How about

var hasAX = "ActiveXObject" in window;
mpdonadio
  • 2,891
  • 3
  • 35
  • 54
  • no, I get false in firefox and chrome from this. see http://jsfiddle.net/qXSvQ/2/ –  Nov 30 '10 at 12:12
  • 5
    @twesh It **should** return false in Firefox and Chrome; neither FireFox nor Chrome support ActiveX. You are running code to determine if FireFox or Chrome support ActiveX. Since neither FireFox or Chrome support ActiveX, the function should return `false`. Testing the actual code in FireFox and Chrome, it correctly returns `false`. Is there something missing from the answer? – Ian Boyd Oct 10 '13 at 14:12
8

Below code should work, It is working on IE6 & FF 3.6.12 atleast.

if(typeof(window.ActiveXObject)=="undefined"){
    alert("ActiveX Object not supported");
}else {
    alert("ActiveX Object  supported");
}
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Chinmayee G
  • 7,947
  • 2
  • 31
  • 41
  • its working fine in `IE`, but in firefox it is undefined. I have checked with `FF 3.6.12` and `FF 4.0b7`. –  Nov 30 '10 at 12:10
  • @twesh, undefined is fine that is ActiveX is not supported in FF. Even in above code also, I've compared it with "undefined" only. – Chinmayee G Nov 30 '10 at 12:12
  • so any workarounds to check if ActiveX is enabled in the FF browser? –  Nov 30 '10 at 12:15
  • 7
    @twesh - Firefox **never** supports ActiveX. As Chinmayee said, Firefox will always return `undefined`. Perhaps you mean something other than ActiveX, if you expect FF to support it? – Andrzej Doyle Nov 30 '10 at 13:31
  • actually I need to check if ActiveX is enabled or not for tracking purpose. how does google analytics detect ActiveX? –  Dec 01 '10 at 18:42
  • @AndrzejDoyle He might be thinking of the binary plug-in system used by Chrome/Netscape/Firefox. All browsers have a binary plug-in system. In Internet Explorer, they are painless to install and called ActiveX. In other browsers they are called [*NPAPI plugins*](http://en.wikipedia.org/wiki/NPAPI). Knowing if the user agent supports NPAPI would be useful for then showing the user a download link (e.g. maps.google.com and the Google Earth NPAPI plugin). But, in the end, the question was about **ActiveX**, not **NPAPI**, so this is the right answer. – Ian Boyd Oct 10 '13 at 14:07
  • According to this IE with the activex settings on doesn't supports activex, even when I can see the `window.ActiveXObject` property in the `window` element, I'd stick with @MPD answer, which shows the correct value – Juan Carlos Alpizar Chinchilla May 10 '14 at 23:35
  • Weird, doesn't seem to work in IE11. It says that window.ActiveXObject is undefined, yet I can still create a new ActiveXObject by writing 'var something = new ActiveXObject("PCDClient.PCDLogin.1");' in the console – Drkawashima Feb 02 '15 at 12:06
  • This answer is not correct on IE11, where it will sometimes create false-negatives. See this screenshot, where ActiveX is clearly available, but `typeof(window.ActiveXObject)' is `undefined`. Philip Pryce's answer below works correctly. https://i.stack.imgur.com/cNknO.png – Chris Vasselli Nov 29 '17 at 23:05
1

It seems Firefox simply skips scripts containing ActiveX objects:

<script><!--
  var activeXsupport = "ActiveX not supported";
// --></script>

<script><!--
  var dummy = new ActiveXObject ('WScript.Shell');
  activeXsupport = "ActiveX supported";
// --></script>

<script><!--
  alert (activeXsupport);
// --></script>    

So this gives me "supported" on IE11 and "not supported" on Firefox.

[Edit:] Since it also throws an error message on Firefox if the console is opened with [F12], I suggest this improvement:

<script><!--   
  var dummy = ''; var hasActiveX = false;  
  try {dummy = new ActiveXObject ('WScript.Shell'); hasActiveX = true;}
  catch (err) {dummy = ''; hasActiveX = false;}
  alert ('hasActiveX = ' + hasActiveX);
// --></script>   

Edge Chromium supports ActiveX if it is made the default browser in settings and reloading in Internet Explorer Mode via "More Tools" is enabled:

edge://settings/defaultBrowser 

Gerolf

Gerolf
  • 11
  • 2