title: How to convert Msxml2.XMLHTTP based IE-only website so it also work with Firefox?
body: <p>This is an IE-only website, which I want to use with other browsers, for example Firefox:</p>
  
  <p><a href="https://golestan.sbu.ac.ir/Forms/AuthenticateUser/login.htm" rel="nofollow noreferrer">https://golestan.sbu.ac.ir/Forms/AuthenticateUser/login.htm</a></p>
  
  <p>I am forced to use this website for my university. It uses <code>Msxml2.XMLHTTP</code>, which is an IE-only feature. I tried to convert it to <code>XMLHttpRequest</code> so it works on Firefox only. This is the Greasemonkey script I've created. Now it does not give error, but it does not work.
  All the functions come from the original script of the website, but they are changed so that they work with <code>XMLHttpRequest</code>.
  If the login script comes up, I'm ok with it. How can I debug this javascript?</p>
  
  <pre><code>// ==UserScript==
  // @name        Golestan Login
  // @namespace   sbu.ac.ir
  // @include     https://golestan.sbu.ac.ir/Forms/AuthenticateUser/login.htm
  // @version     1
  // @grant       none
  // ==/UserScript==
  
  var isInternetExplorer = 0;
  
  function check(){
    var x;
  if (window.XMLHttpRequest) {
    x = new XMLHttpRequest();
  } else {
    try { 
      x = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try { 
        x = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        x = false; 
      }
    }
  }
    x.open("HEAD",document.location,true);
    x.send();
    var sd=new Date(x.getResponseHeader('Last-Modified'));
    var cd=new Date(document.lastModified);
    if(sd-cd&gt;3660000){
      document.cookie = "reloading=1";
      window.location.reload(true);
      return false;
    }
    return true;
  }
  
  
          function a(){
              for (k = 0; k &lt; nall; k++) {
                  td = document.createElement('TD');
                  td.className = 'e';
                  Pr.appendChild(td);
              }
              if (!check()) {
                  //window.open("/_Templates/howtoclearcache.htm","_blank");
                  //top.close();
                  return;
              }
              var aCookie = document.cookie.split("; ");
              var cook=0;
              for (var i=0; i &lt; aCookie.length; i++)
              {
                  var aCrumb = aCookie[i].split("=");
                  if ("reloading" == aCrumb[0]) {
                      cook=unescape(aCrumb[1]);
                      break;
                  }
              }
              var ind=0;
              for( i=0;i&lt;all.length;i=i+2){
                  if(all[i+1]==1)
                      for(j=0;j&lt;4;j++){
    var r;
  if (window.XMLHttpRequest) {
    r = new XMLHttpRequest();
  } else {
    try { 
      r = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try { 
        r = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        r = false; 
      }
    }
  }
  
  
                          r.open("GET", all[i]+imstat[j]+".gif", true);
                          if(cook==1) r.setRequestHeader('If-Modified-Since','Sat,01 Jan 2000 00:00:00 GMT');
                          getobj(r,ind++);
                      }
                  else{
    var r;
  if (window.XMLHttpRequest) {
    r = new XMLHttpRequest();
  } else {
    try { 
      r = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try { 
        r = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        r = false; 
      }
    }
  }                   r.open("GET", all[i], true);
                      if(cook==1) r.setRequestHeader('If-Modified-Since','Sat,01 Jan 2000 00:00:00 GMT');
                      getobj(r,ind++);
                  }
              }
              document.cookie = "reloading=0; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
          }
  
  function main_DoFSCommand(command, args) {
      var mainObj = document.all.main;
      //
      // Place your code here.
      //
      document.getElementById("rdir").style.visibility = "hidden";
      if(command != "showmenu")
      if(command == "Animation_Complete")
      {
          var x = 0;
          var y = 0;
          x = main.clientHeight/2 - 300;
          y = main.clientWidth/2 - 400;
          document.getElementById("iframeNews").style.top = x + 120;
          document.getElementById("iframeNews").style.left = y + 264;
          modifySrc();
          document.getElementById("iframeNews").style.visibility = "visible";
  
      }
      else
      {
          if(command == "Enter")
          {
              bal('main');
          }
          else if(command == "Education")
          {
              bal('test');
          }
          else
              document.getElementById("iframeNews").style.visibility = "hidden";
      }
  }
  
  // http://stackoverflow.com/questions/21271997
  addJS_Node (check);
  addJS_Node (a);
  addJS_Node (main_DoFSCommand);
  
  isInternetExplorer=true;
  
  function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
      var D                                   = document;
      var scriptNode                          = D.createElement ('script');
      if (runOnLoad) {
          scriptNode.addEventListener ("load", runOnLoad, false);
      }
      scriptNode.type                         = "text/javascript";
      if (text)       scriptNode.textContent  = text;
      if (s_URL)      scriptNode.src          = s_URL;
      if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';
  
      var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
      targ.appendChild (scriptNode);
  }
  </code></pre>
  
  <p>I think this work is worth doing, because hundreds of thousans of users, which are university students, are affected.</p>
  
  <p>Update: We could be able to go one level further, and reach <code>main.htm</code>. So, I wrote another script for this page. But, at last I get <code>ReferenceError: element is not defined[Learn More]</code>.</p>
  
  <pre><code>// ==UserScript==
  // @name        Golestan Main
  // @namespace   sbu.ac.ir
  // @include     https://golestan.sbu.ac.ir/Forms/AuthenticateUser/main.htm
  // @version     1
  // @grant       none
  // ==/UserScript==
  
  // Microsoft WebService Behavior (Predecessor of modern AJAX)
  // Information: https://web.archive.org/web/20060101200359/https://msdn.microsoft.com/workshop/author/webservice/webservice.asp
  // JavaScript version: https://raw.githubusercontent.com/nzakas/professional-javascript/master/edition1/ch17/webservice.htc
  
  // NOTE: You should paste the Javascript code from the above URL here
  
  // end Microsoft WebService Behavior
  
  
  function l(){
              useService("../f0241_process_authexit/authexit.asmx?WSDL", "get");
  //            useService("authuser.asmx?WSDL", "get");
              mt = new MainTit(document,titH);
              mt.Maxi();
              t = new Tab(document,titH,0,document.body.clientWidth,document.body.clientHeight-titH);
              t.maintitle=mt;
              OpenFaci('صفحه اصلي','nav.htm?fid=0;1&amp;tck='+'&amp;'+location.search.replace('?',''));
              mt.HideGTit();
              KeysValues = location.search.split(/[\?&amp;]+/);
              for (i = 0; i &lt; KeysValues.length; i++) {
                      KeyValue = KeysValues[i].split("=");
                      if (KeyValue[0] == "CSURL") {
                          CSURL = KeyValue[1];
                          break;
                      }
              }
          }
  
  function ex(ltck,tck,u,si,ft,fid,sess){
              var co = createCallOptions();
                  co.funcName = "ex";
                  co.async = false;
              // callService(function(result){if(result.error){/*alert(result.errorDetail.string);*/}},"ex",ltck,tck,u,si,ft,fid,sess);
                  callService(co,ltck,tck,u,si,ft,fid,sess);
  
  }
  
  
  addJS_Node (l);
  addJS_Node (ex);
  
  addJS_Node(ErrDetail);
  addJS_Node(postError);
  addJS_Node(returnError);
  addJS_Node(createCallOptions);
  addJS_Node(createUseOptions);
  addJS_Node(cloneObject);
  addJS_Node(ensureVBArray);
  addJS_Node(encb64hlp);
  addJS_Node(decb64hlp);
  addJS_Node(encb64);
  addJS_Node(decb64);
  addJS_Node(ensureWsdlUrl);
  addJS_Node(allocCall);
  addJS_Node(fnShowProgress);
  addJS_Node(isSimpleType);
  addJS_Node(isPrimitive);
  addJS_Node(getSdl);
  addJS_Node(processService);
  addJS_Node(onImportLoaded);
  addJS_Node(loadImports);
  addJS_Node(invokeNext);
  addJS_Node(callNext);
  addJS_Node(getAttrib);
  addJS_Node(getBaseName);
  addJS_Node(getQualifier);
  addJS_Node(getNextNsq);
  addJS_Node(getUniqueNsq);
  addJS_Node(parseSimpleType);
  addJS_Node(parseType);
  addJS_Node(parseArrayType);
  addJS_Node(parseComplexType);
  addJS_Node(parseAttrib);
  addJS_Node(parseElem);
  addJS_Node(parseSoapHeader);
  addJS_Node(expBase);
  addJS_Node(parseSchemas);
  addJS_Node(parseSdl);
  addJS_Node(ensureXmlHttp);
  addJS_Node(encodeHeader);
  addJS_Node(_invoke);
  addJS_Node(callService);
  addJS_Node(useService);
  addJS_Node(getMsg);
  addJS_Node(fixupDT);
  addJS_Node(encTZ);
  addJS_Node(encodePrimitive);
  addJS_Node(bldJsAry);
  addJS_Node(getNextIndexAry);
  addJS_Node(vbArrayToJs);
  addJS_Node(encodeArray);
  addJS_Node(encodeVar);
  addJS_Node(getArySize);
  addJS_Node(get1stAryItem);
  addJS_Node(getAryItemFromIndex);
  addJS_Node(getSchema);
  addJS_Node(getArySizeInfo);
  addJS_Node(encodeAttrib);
  addJS_Node(serPart);
  addJS_Node(getWrap);
  addJS_Node(encodeArgs);
  addJS_Node(returnResult);
  addJS_Node(decTZ);
  addJS_Node(applyTZ);
  addJS_Node(decDate);
  addJS_Node(decTime);
  addJS_Node(decodePrimitive);
  addJS_Node(getAryInfo);
  addJS_Node(decodeArray);
  addJS_Node(decodeAryItem);
  addJS_Node(getAryElem);
  addJS_Node(decodeElem);
  addJS_Node(decodeType);
  addJS_Node(processResult);
  addJS_Node(hideProgress);
  addJS_Node(getResult);
  
  
  function addJS_Node (text, s_URL, funcToRun, runOnLoad) {
      var D                                   = document;
      var scriptNode                          = D.createElement ('script');
      if (runOnLoad) {
          scriptNode.addEventListener ("load", runOnLoad, false);
      }
      scriptNode.type                         = "text/javascript";
      if (text)       scriptNode.textContent  = text;
      if (s_URL)      scriptNode.src          = s_URL;
      if (funcToRun)  scriptNode.textContent  = '(' + funcToRun.toString() + ')()';
  
      var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement;
      targ.appendChild (scriptNode);
  }
  </code></pre>