【发布时间】:2017-08-06 06:32:30
【问题描述】:
我正在按如下方式加载 PDF(我使用的是 Angular 2,但我不确定这是否重要..):
//Inside a service class
downloadPdf = (id): Observable<Blob> => {
let headers = new Headers();
headers.append("Accept", "application/pdf");
return this.AuthHttp.get(this.pdfURL + id, {
headers: headers,
responseType: ResponseContentType.Blob
}).map(res => new Blob([res.blob()], {type: "application/pdf"}));
}
//Inside a click handler
this.pdfService.downloadPdf(this.id).subscribe((data: Blob) => {
let fileURL = window.URL.createObjectURL(data);
window.open(fileURL);
});
此代码在 Firefox 中运行良好。在 Chrome 中,新标签页会短暂闪烁打开和关闭。当我调试并手动将 surf 到对象 URL 时,Chrome 可以正常打开它。
我在这里做错了什么?
【问题讨论】:
-
你有 AdBlock Plus 或任何其他类型的广告块扩展的机会吗?我在使用几乎相同的代码时遇到了同样的问题,但在禁用 AdBlock Plus 后问题就消失了。
标签: google-chrome angular pdf