需要在IE窗口中打开blob/PDF

Spa*_*y74 15 javascript internet-explorer google-chrome typescript

我在我的打字稿中有下面的代码来调用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
            });
        });
    }
Run Code Online (Sandbox Code Playgroud)

此代码在Chrome中运行良好.该文件按预期打开.然而,IE问"你想让这个网站在你的电脑上打开一个应用程序吗?" 如果允许,请告诉我"没有安装应用程序来打开这种链接(blob)".

有关如何在新选项卡中打开它或将blob保存为文件作为最后手段的任何想法?

les*_*syk 3

它在 Chrome 和其他普通浏览器中工作的原因是:它们内部安装了 pdf 预览器。

为什么它在 IE 中不起作用:因为在架构上,如果 IE 应该在操作系统上安装一些 PDF 阅读程序;例如,如果您安装了 Adob​​e Acrobat,则可以毫无问题地打开它。

我可以推荐您使用:pdf.js/