gpt4 book ai didi

javascript - 当您收到来自服务器的 blob 响应时,如何填充提示浏览器窗口?

转载 作者:行者123 更新时间:2023-11-27 23:03:22 25 4
gpt4 key购买 nike

我在kendo网格上有exportChallenges按钮,可以使用angularJs工厂将网格数据导出到excel,我从服务器端收到了休息服务响应(Blob),但它没有提示浏览器上的用户保存、打开或下载选项。

如何使用 Angularjs 或 native JavaScript 解决此问题?

导出.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);
});
};

最佳答案

打开 blob 取决于浏览器(即 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);
}

关于javascript - 当您收到来自服务器的 blob 响应时,如何填充提示浏览器窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36843777/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com