为什么不能在以下演示中打开链接:http:
//html5-demos.appspot.com/static/a.download.html
您甚至无法右键单击并在新选项卡/窗口中打开它.我需要自定义浏览器中的任何设置吗?
似乎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)