相关疑难解决方法(0)

在IE11中打开由createObjectURL创建的链接

为什么不能在以下演示中打开链接:http:
//html5-demos.appspot.com/static/a.download.html

您甚至无法右键单击并在新选项卡/窗口中打开它.我需要自定义浏览器中的任何设置吗?

html javascript internet-explorer blob

61
推荐指数
2
解决办法
5万
查看次数

如何在IE的新标签页中显示PDF而不下载它

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

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

html javascript cross-browser angular

5
推荐指数
1
解决办法
4396
查看次数