javascript - How to use a connection to create a dynamic download file stream in ie11?
phpcn_u1582
phpcn_u1582 2017-05-19 10:08:47
0
1
609

The following function can download a txt file in other browsers, but jumps to a blank page in ie11. The file is URL-encoded and placed in the address bar. No download is triggered. How can I trigger downloading files in IE11?

Full project address: https://github.com/wangduandu...

    this.downloadLog = function() {
        var file = "data:text/plain;charset=utf-8,";
        var logFile = self.getLog();
        var encoded = encodeURIComponent(logFile);
        file += encoded;
        var a = document.createElement('a');
        a.href = file;
        a.target   = '_blank';
        a.download = self.formatTimestamp()+ '-' + self.logFilename;
        document.body.appendChild(a);
        a.click();
        a.remove();
    };

phpcn_u1582
phpcn_u1582

reply all(1)
PHPzhong

After checking the information, you can use Microsoft’s exclusive msSaveBlob. This method supports ie10 and above.

var downloadFileName = self.formatTimestamp()+ '-' + self.logFilename;

        if(window.navigator.msSaveBlob){
            // for ie 10 and later
            try{
                var blobObject = new Blob([self.output]); 
                window.navigator.msSaveBlob(blobObject, downloadFileName); 
            }
            catch(e){
                console.log(e);
            }
        }
        else{
            var file = "data:text/plain;charset=utf-8,";
            var logFile = self.output;
            var encoded = encodeURIComponent(logFile);
            file += encoded;
            var a = document.createElement('a');
            a.href = file;
            a.target   = '_blank';
            a.download = downloadFileName;
            document.body.appendChild(a);
            a.click();
            a.remove();
        }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template