2017-01-23 112 views
0

我已經使用JS for IE9創建了新的下載功能,但它不起作用。ie9 javascript下載功能不起作用

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(); 
     } 

我讀到,在IE9中沒有Blob類型,所以xhr.response返回undefined。我該如何解決它?

+2

你是否在stackoverflow上搜索解決方案,似乎已經有人問過這個問題? IE9 Blob Polyfill – epascarello

+0

是的,但我有很多沒有答案的問題。 –

+0

那麼你不能使用Ajax,而是提交一個表單並讓服務器設置下載標題。 – epascarello

回答

0

看看這個答案:https://stackoverflow.com/a/1926163/2435443

他用注射的VBScript (的ActiveXObject)以字節字符串轉換爲二進制數組,它是一種無對象定義斑點「仿真」的。看起來很快&健壯。