zoukankan      html  css  js  c++  java
  • [转] 如何在ie11里使用a连接创建动态下载文件流

    [From] https://segmentfault.com/q/1010000009470664

    查了资料,可以使用微软独家的msSaveBlob, 这个方法支持ie10及以上。

    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();
            }
  • 相关阅读:
    hashlib模块
    configparser模块
    xml模块和shelve模块
    json与pickle模块
    3/30
    os模块
    sys模块
    shutil模块
    random模块
    2月书单《编码隐匿在计算机软硬件背后的语言》 13-16章
  • 原文地址:https://www.cnblogs.com/pekkle/p/8428110.html
Copyright © 2011-2022 走看看