0

I've created new download function using JS for IE9, but it doesn't work.

descargarArchivo : function (url, idlote) {
            var str = window.location.href+"/"+url;
            str = str.replace("form.do/", "");
            // Le da nombre del fichero que se va a descargar
            var filename = 'factura_'+idlote;
            xhr= new XMLHttpRequest(); 
            xhr.responseType = 'blob';
            xhr.onload = function() {
                      var a = document.createElement('a');
                      a.href = window.URL.createObjectURL(xhr.response); 
                      a.download = filename; // Set the file name.
                      a.style.display = 'none';
                      document.body.appendChild(a);                         
                      a.click();
                      delete a;
                  }
               } 
           };
           xhr.open('GET', str);
           xhr.send();
        }

I read that, in IE9 there is no Blob type, so xhr.response returns undefined. How can I resolve it?

Stefan Zahariev
  • 41
  • 1
  • 1
  • 5

1 Answers1

0

Look at this answer : https://stackoverflow.com/a/1926163/2435443

He uses injected VBScript (ActiveXObject) to convert byte strings to binary array, it's a kind of Blob 'emulation' without the object definition. Looks fast & robust.

Community
  • 1
  • 1
Sir McPotato
  • 899
  • 7
  • 21