download attribute in html5 doesn't work at all in any web browser

问题描述 投票:0回答:2

**我的代码段

<button ><a href="Palak_Lohia_Resume.pdf" download class="button4"> </a></button>

It just opens the pdf file in other tab but doesn't force the download.
php html
2个回答
0
投票

根据官方文档,下载方法仅在此浏览器上有效:

- List item

[之后,您需要重新调用并确保download属性始终写在<a>标记的末尾。我的意思是,像这样:

<a href="yourfile.pdf" download>

因为如果在中间将其用作:

<button ><a href="Palak_Lohia_Resume.pdf" download class="button4"> </a></button>

浏览器可能会丢失该属性,因此这是您的<a>无法使用的属性。

还要确保您的文件与逻辑文件位于同一级别。否则,请使用absolute路径代替relative路径,这对浏览器的帮助可以获取您的文件并将其发送下载。

您可以在此处阅读有关此内容的更多详细信息:https://www.w3schools.com/tags/att_a_download.asp


0
投票

尝试将下载内容放在标签的末尾

<button ><a href="Palak_Lohia_Resume.pdf" class="button4" download> </a></button>

或放置download =“ true”

<button ><a href="Palak_Lohia_Resume.pdf" class="button4" download="true"> </a></button>
© www.soinside.com 2019 - 2024. All rights reserved.