How to download multiple files in one shot in IE

前端 未结 4 998
Happy的楠姐
Happy的楠姐 2021-01-05 05:40

I want to download multiple files on click of a button in jsp.
I am using the following code in the js to call one servlet twice.

var iframe = document.c         


        
4条回答
  •  庸人自扰
    2021-01-05 06:08

    It can be done by creating a blob using the file source URL. I have tested this with image and PDF files in IE 11.

                    if (navigator.msSaveBlob) {
                        var xhr = new XMLHttpRequest();
                        xhr.open('GET', file_url, true);
                        xhr.responseType = 'blob';
    
                        xhr.onload = function(e) {
                           if (this.status == 200) {
                               var blob = this.response;
                               navigator.msSaveBlob(blob, file_name);
                           }
                        }
    
                        xhr.onerror = function(e) {
                            alert("Error " + e.target.status + " occurred while receiving the document.");
                        }
    
                        xhr.send();
                    }
    

    I got this idea when I came across this: Getting BLOB data from XHR request

提交回复
热议问题