首页 > 解决方案 > 使用被 Chrome 广告块阻止的 Angular 中的 blob 渲染 PDF

问题描述

我的设置如下:

getDocumentPdf(name: string) {
this.pdfService.getPdfFile(name).subscribe((data) => {
  const file = new Blob([data], {type:'application/pdf'});
  const fileUrl = URL.createObjectURL(file);
  window.open(fileUrl);
});

}

和 pdfService 是:

getPdfFile(name: string) {
    const url = environment.apiUrl + '/files/';
    const httpOpt = {
        'responseType': 'arraybuffer' as 'json'
    };

    return this.http.get<any>(url + name, httpOpt);
}

使用 chrome 时,弹出窗口被阻止。使用隐身可以解决问题,但我希望用户使用标准浏览器访问它。

亲切的问候,

标签: angulartypescriptadblock

解决方案


推荐阅读