gpt4 book ai didi

angular - 如何在 Angular 6 中单击按钮下载 pdf 文件

转载 作者:行者123 更新时间:2023-12-03 23:10:40 25 4
gpt4 key购买 nike

我想点击按钮下载 .pdf 文件我正在使用下面的代码

downloadMyFile() {
const link = document.createElement('a');
link.setAttribute('target', '_blank');
link.setAttribute('href', 'http://designs.mydeievents.com/jq-3d-flip-book/books/pdf/aqua_imagica_visit_learnings.pdf');
link.setAttribute('download', 'aqua_imagica_visit_learnings.pdf');
document.body.appendChild(link);
link.click();
link.remove();
}

<button (click)="downloadMyFile()">download File</button>

但是当我点击按钮时,它被重定向到一个新页面,但我想下载“aqua_imagica_visit_learnings.pdf”文件。
请帮助我。
这是我的链接 [ http://stackblitz.com/edit/angular-4hjad7]

最佳答案

根据 this如果您在 anchor 上使用下载属性,则不会下载 .pdf 文件:

Some file types, however, (such as images, .pdf, .txt, and .doc for example) won’t be downloaded. They, instead, will be opened in the browser.

关于angular - 如何在 Angular 6 中单击按钮下载 pdf 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58003749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com