2016-04-25 6 views
1

私は012Jボタンを剣道グリッドに持っていて、cornerJsファクトリを使用してグリッドデータをエクスポートすると、サーバー側からレスポンスサービスレスポンス(Blob)が受信されましたが、ブラウザ上で保存、開く、またはダウンロードするためのユーザーに対してプロンプトが表示されません。サーバからのBLOBレスポンスを受け取ったときに、プロンプトブラウザウィンドウに値を設定するには?

AngularjsまたはネイティブJavaScriptを使用してこの問題を解決するにはどうすればよいですか?

export.jsブロブを開く

$scope.exportChallenges = function() { 
     processFactory.exportPrcChallenges($stateParams.processId, challengeType); 
     .success(function(response) { 
      var blob = new Blob([response.data], { 
       type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" 
      }); 
      debugger; 
      var objectUrl = URL.createObjectURL(blob); 
      window.open(objectUrl); 
     }); 
    }; 

答えて

1

(つまり、IEはAPIで独自の実装を持っている)、ブラウザに依存します。これを行う:

var blob = new Blob([response.data], {type: contentType}); 

//call the save blob API in IE 
if(window.navigator && window.navigator.msSaveOrOpenBlob) { 
    //save or open prompt in IE 
    //there's a save prompt too, depending on what you need 
    window.navigator.msSaveOrOpenBlob(blob, "filename"); 
} else { //other browsers 
    var objectUrl = URL.createObjectURL(blob); 
    window.open(objectUrl); 
} 
関連する問題