javascriptreactjsactivexobject

'ActiveXObject' is not defined no-undef [React-Js]


I am trying to parse XML Response un ReactJs.

var parser, xmlDoc;
var text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";

if (window.DOMParser) {
    // code for modern browsers
    parser = new DOMParser();
    xmlDoc = parser.parseFromString(text,"text/xml");
  } else {
    // code for old IE browsers
  xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async = false;
    xmlDoc.loadXML(text);
  }

Above code works fine in React if i remove else part , but project requirement is to support >=IE7 browsers using ReactJs. Also above code is working good if i embed JS into simple HTML page. Please let me know if i am missing something.


Solution

  • So use window.ActiveXObject instead of just ActiveXObject to get around the global. I assume your linter is set up to allow window.

    or set up your linter to allow it

    "eslintConfig": {
      "globals": {
        "window": true,
        "ActiveXObject": true
      }
    }
    

    or set it on the page

    /* global ActiveXObject */