我想使用$http下载exe文件,它在我控制数据时显示我,但我无法下载它.
$http({ url: url,method: "GET",headers: { 'Content-type': 'application/json' } }).success(function (data,status,headers,config) { console.log(data); window.open(objectUrl); }).error(function (data,config) { //upload Failed });
任何帮助,将不胜感激.
解决方法
Given code will help you to download exe file as well as to check
browser compatibility.
var ieEDGE = navigator.userAgent.match(/Edge/g); var ie = navigator.userAgent.match(/.NET/g); // IE 11+ var oldIE = navigator.userAgent.match(/MSIE/g); var blob = new window.Blob([data.data],{ type: 'application/x-msdownload' }); if (ie || oldIE || ieEDGE) { var fileName="filename"+'.exe'; window.navigator.msSaveBlob(blob,fileName); } else { var file = new Blob([ data.data ],{ type : 'application/x-msdownload' }); var fileURL = URL.createObjectURL(file); var a = document.createElement('a'); a.href = fileURL; a.target = '_blank'; a.download = "filename"+'.exe'; document.body.appendChild(a); a.click(); } //Successfully Downloaded