如何在IE的新标签页中显示PDF而不下载它 [英] How to show PDF in a new tab of IE without downloading it

查看:64
本文介绍了如何在IE的新标签页中显示PDF而不下载它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎IE不允许直接打开Blob.您必须使用msSaveOrOpenBlob.但是,有什么办法可以将其转换.我确实需要在不下载IE的情况下将其显示到IE的新标签中,或者至少用户不应进行交互,也不要看到将其下载到例如IE中.系统临时文件夹.Safai在同一窗口而不是新选项卡中打开它,但是主要问题是IE.使所有浏览器工作类似并在新标签页中打开以进行预览的主要思想.

Seems IE won't allow to open blobs directly. You have to use msSaveOrOpenBlob. But is there any way to convert it somehowe then. I do need to show PDF into a new tab of IE without downloading it or at least user should not interact and don't see it's being downloaded into e.g. system temp folder. Safai opens it in same window instead of a new tab but main problem is IE. The main idea to make all browsers work similar and open it in new tab for preview.

let blob = new Blob([response], {
    type: 'application/pdf'
});

if (window.navigator && window.navigator.msSaveOrOpenBlob) {//IE
    window.navigator.msSaveOrOpenBlob(response, "TheDocumentToShow.pdf");
} else {
    var fileURL = URL.createObjectURL(response);
    if (navigator.userAgent.indexOf("Chrome") != -1 || navigator.userAgent.indexOf("Firefox") != -1){
        let win = window.open(fileURL, '_blank');                        
    } else { //Safari & Opera iOS
        window.location.href = fileURL;
    }
}

推荐答案

您可以使用此库:https://github.com/VadimDez/ng2-pdf-viewer .它基于 pdfjs 构建,并且可以将pdf集成到您自己的页面中.您可以创建将链接作为参数的路由,并在新标签页中打开它.

you could use this library: https://github.com/VadimDez/ng2-pdf-viewer. It is build on pdfjs and can integrate a pdf into your own page. You can create a route which takes a link as paramater and open that in a new tab.

这篇关于如何在IE的新标签页中显示PDF而不下载它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆