简体   繁体   English

单击 HTML 链接<a>到其他网站</a>时如何触发文件下载

[英]How to trigger a file download when clicking an HTML Link <a> to other website

I had read the following:我已阅读以下内容:
How to trigger a file download when clicking an html <a> tag or javascript in a modern browser 如何在现代浏览器中单击 html <a> 标签或 javascript 时触发文件下载
How to trigger a file download when clicking an HTML button or JavaScript 单击 HTML 按钮或 JavaScript 时如何触发文件下载

For me isn't working.对我来说不起作用。
I have a link to a file https://childrensradiofoundation.org/wp-content/uploads/2020/09/2020_COVID19-_RemoteOutreach_Campaigns_English_D3.pdf and I want to download the file:我有一个指向文件https://childrensradiofoundation.org/wp-content/uploads/2020/09/2020_COVID19-_RemoteOutreach_Campaigns_English_D3.pdf的链接,我想下载该文件:

<a class="nav-link" href="https://childrensradiofoundation.org/wp-content/uploads/2020/09/2020_COVID19-_RemoteOutreach_Campaigns_English_D3.pdf" download>Download</a>

The code above open a new tab with the link and doesn't download the file.上面的代码打开一个带有链接的新选项卡,并且不下载文件。
Any suggestions with simple JavaScript if plain HTML not working?如果普通 HTML 不起作用,有什么简单的 JavaScript 建议吗?
I don't want a button (the link is in Nav Bar).我不想要一个按钮(链接在导航栏中)。

LATER EDIT: As @Lundstromski suggest bellow, there is no way to do that.后期编辑:正如@Lundstromski 建议的那样,没有办法做到这一点。

The link works as intended for me with a dummy file.该链接使用虚拟文件按预期工作。

 <a class="nav-link" href="https://file-examples-com.github.io/uploads/2017/02/file-sample_500kB.docx" download>Download</a>

Its a error of that website that file does not exist: Look here this works:该文件不存在是该网站的错误:看这里可行:

    <a class="nav-link" href="https://file-examples-com.github.io/uploads/2017/02/file-sample_500kB.docx" download>Download</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM