Search code examples
c#javascriptactivexmodernizr

How can I detect ActiveX support?


I know that Modernizr hasn't got a built-in test for ActiveX and detecting ActiveX support for IE gets complicated after IE11 (look at Silverlight version detection code).

Is there any workaround for detecting ActiveX support all versions of IE and other browsers? Also I have to control this server-side too and Request.Browser.ActiveXControls returns false on IE11 (This issue has been reported Microsoft).


Solution

  • You can use the following script for client-side and if you save it to element, you can access it via server-side.

    function IsActiveXSupported() {
        var isSupported = false;
    
        if(window.ActiveXObject) {
            return true;
        }
    
        if("ActiveXObject" in window) {
            return true;
        }
    
        try {
            var xmlDom = new ActiveXObject("Microsoft.XMLDOM");
            isSupported = true;
        } catch (e) {
            if (e.name === "TypeError" || e.name === "Error") {
                isSupported = true;
            }
        }
    
        return isSupported;
    }