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

后端 未结 4 771
萌比男神i
萌比男神i 2020-12-06 05:04

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 wo         


        
相关标签:
4条回答
  • 2020-12-06 05:16

    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");
    }
    
    0 讨论(0)
  • 2020-12-06 05:18

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

    var hasAX = "ActiveXObject" in window;
    0 讨论(0)
  • 2020-12-06 05:39

    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 */ }
    
    0 讨论(0)
  • 2020-12-06 05:41

    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

    0 讨论(0)
提交回复
热议问题