【问题标题】:Need to open blob/PDF in IE window需要在 IE 窗口中打开 blob/PDF
【发布时间】: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 保存为文件作为最后手段的任何想法?

【问题讨论】:

标签: javascript google-chrome internet-explorer typescript


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-01
    • 2013-03-07
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多