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下有問題,不推薦

 

 

發佈了38 篇原創文章 · 獲贊 9 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章