【发布时间】:2016-03-30 03:36:29
【问题描述】:
我的打字稿中有以下代码,用于调用 Web api 方法并检索 PDF 格式的二进制字节数组 (blob)。我的用户要求是在新窗口中打开 PDF。
$scope.selectRow = (itemImageNumber: string, printProcessId: string, printXmlId: string) => {
itemService.GetOutgoingDocument($scope.item.ItemId, itemImageNumber, printProcessId, printXmlId).success((response) => {
var file = new Blob([response], { type: 'application/pdf' });
var fileUrl = URL.createObjectURL(file);
//$scope.outDocContent = $sce.trustAsResourceUrl(fileUrl);
var win = window.open($sce.trustAsResourceUrl(fileUrl));
win.focus();
}).error(() => {
var message =
"The document you selected can’t be displayed at this time. Please call Customer Service at xxx-xxx-xxxx for assistance.";
$rootScope.$broadcast("app-message", {
type : "danger",
message : message
});
});
}
此代码在 Chrome 中运行良好。文档按预期打开。然而,IE 会询问“你想允许这个网站在你的计算机上打开一个应用程序吗?”如果允许,请告诉我“没有安装任何应用程序来打开这种链接 (blob)”。
关于如何在新选项卡中打开它或将 blob 保存为文件作为最后手段的任何想法?
【问题讨论】:
-
猜想:有一些看起来相似的问题可能会有所帮助:stackoverflow.com/questions/28196065/…, stackoverflow.com/questions/24007073/… 特别是这个 IE 特定的行可能很有趣:
window.navigator.msSaveOrOpenBlob(blobObject, fileName);
标签: javascript google-chrome internet-explorer typescript