javascript - 需要在IE窗口打开blob/PDF

标签 javascript google-chrome internet-explorer typescript

我的 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
            });
        });
    }

此代码在 Chrome 中运行良好。文档按预期打开。然而,IE 会询问“您要允许此网站在您的计算机上打开应用程序吗?”当允许时,告诉我“没有安装任何应用程序来打开这种链接(blob)”。

作为最后的手段,关于如何在新选项卡中打开它或将 blob 另存为文件有什么想法吗?

最佳答案

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

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

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

关于javascript - 需要在IE窗口打开blob/PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34440114/

相关文章:

javascript - Internet Explorer Javascript 性能问题

javascript - IE 中的事件未定义在 Firefox 中有效

css - IE 不设置 HTML5 标签的样式(使用 shiv)

javascript - 如何找到真正的DIV高度?

javascript - 这些按钮不会改变文本颜色或图像大小。我认为我的 javascript 链接不正确?

javascript - 如何在闭包中卡住函数的变量?

twitter-bootstrap - 卡片列嵌入推文 : Difference Between Chrome and other browsers

javascript - 在 Chrome 扩展内容脚本中使用现有的 jQuery?

javascript - ajax调用中的 Accordion Jquery和页面高度

javascript - 将 div 包裹在 img 宽度周围并保持 div 100% 高