IE浏览器点击下载文件

// 下载
          $.ajax({
            url:window.SITE_CONFIG.baseUrl+'/sjyp/yqfx/exportWord',
            method:'get',
            responseType:'blob',
            data:{
              token:this.$cookie.get("zdtoken"),
              fileName:row.bt
            }
          }).success(function(response, status, header, config, statusText){
            var blob = new Blob([response], { type: 'application/vnd.ms-word' });
            var fileName = row.bt + '.docx';

            if (window.navigator.msSaveOrOpenBlob) {// For IE浏览器
              navigator.msSaveBlob(blob, fileName);
            } else { // For 其他浏览器
              var objectUrl = URL.createObjectURL(blob);
              var a = document.createElement('a');
              document.body.appendChild(a);
              a.setAttribute('style', 'display:none');
              a.setAttribute('href', objectUrl);
              a.setAttribute('download', fileName);
              a.click();
              URL.revokeObjectURL(objectUrl);
            }
          }).error(function(data,header,config,status){
           console.log('error')
          });

使用window.location.href在IE下有问题,不推荐

发布了37 篇原创文章 · 获赞 8 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/qq_34122822/article/details/103559913