簡體   English   中英

ie9 javascript 下載功能不起作用

[英]ie9 javascript download function doesn´t work

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

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返回未定義。 我該如何解決?

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

他使用注入的VBScript (ActiveXObject)將字節字符串轉換為二進制數組,這是一種沒有對象定義的Blob“模擬”。 看起來快速而堅固。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM