title: Create Xml document based on the browser using Javascript
body: <p>I am trying to get an older application to work in Chrome and Edge. It currently works only in Compatibility Mode. I have narrowed it down to where it gets the browser type and then creates the xml document based on the browser type.</p>
  
  <pre><code>    // Identify and return the browser type
      function getBrowserType()
      {
          try
          {
              if (typeof ActiveXObject != 'undefined')
              {
                  //Microsoft Internet Explorer
                  return 'MSIE';   
              }
              else if (typeof document != 'undefined'
                  &amp;&amp; document.implementation
                  &amp;&amp; document.implementation.createDocument
                  &amp;&amp; typeof DOMParser != 'undefined')
              {
                  //Other browsers
                  return 'OTH';    
              }
          }
          catch(ex)
          {
              alert('Unable to find browser type.\n' + ex.message);
          }
      }
  //create the xml DOM by browser detection
  
      function createDoc(browserType)
  {
       var xmlDOM = null;
          if (browserType == 'MSIE')
          {
              try 
              {
                  var names = [   'Msxml2.DOMDocument.6.0',
                                  'Msxml2.DOMDocument.3.0',
                                  'MSXML2.DOMDocument',
                                  'MSXML.DOMDocument',
                                  'Microsoft.XMLDOM'      ];
                  for (var key in names)
                  {
                      try
                      {
                          xmlDOM = new ActiveXObject(names[key]);
                      }
                      catch(ex)
                      {}
                  }
              }
              catch(ex)
              {
                  alert('Unable to create XML Document.\n' + ex.message);
              }
          }
          else if (browserType == 'OTH')
          {
              try
              {
                  xmlDOM = document.implementation.createDocument("", "", null);
              }
              catch(ex)
              {
                  alert('Unable to create XML Document.\n' + ex.message);
              }
          }
  
  
          return xmlDOM;
      }
  </code></pre>
  
  <p>So the object that is created is incorrect and it will not create the xml document. If the object created is the ActiveXObject, in Compatibility Mode, it has no problem. So this is based on the browser. So I basically need a way for this to work in all browsers. I think there may be a better way to do this as this is very old 2009 code. </p>