Search code examples
javascriptbackbone.jsactivexactivexobjectactivex-documents

How to replace active x control form javascript project


I am currently working on javascript project which uses backbone.js as the framework. its a pretty old project where Activex components are used in it, now i need to replace this controls completely so that even when i have my active x disabled my functionality should work as expected. How can i achieve this ? Here is my below chunk of a code which can be refereed . Thank you

function getXMLRequest() {
  var xmlHttp = null;
  if (location.protocol.substr(0, 4) == "http") {
    try { // Firefox, Opera 8.0+, Safari  
      xmlHttp = new XMLHttpRequest();
    } catch (e) { // Internet Explorer  
      try {
        // i need to replace these activex controls
        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  } else {
    xmlHttp = new XMLCclRequest();
  }

  return xmlHttp;
}

Solution

  • That code only uses ActiveX if the browser has no native support for XMLHttpRequest.

    i.e. If the browser is Internet Explorer 7 or earlier.

    Nobody should be using that browser today. It doesn't get security updates. It doesn't run on operating systems that get security updates.

    So:

    function getXMLRequest() {
        return new XMLHttpRequest();
    }
    

    If you need to support such horrifically obsolete browsers, then you'll need to change the code on server and client to use JSONP.