HTML5中a标签的download属性

标签:html5

基本用法

1.不修改下载文件的名

<a href="large.jpg" download>下载</a>

2.指定下载文件名:

<a href="83500700-1542865507.59.wav" download="362.wav">下载</a>

如果后缀名一样,我们还可以缺省,直接文件名:

<a href="83500700-1542865507.59.wav" download="362">下载</a>

限制

  • This attribute only works for same-origin URLs.
  • Although HTTP(s) URLs need to be in the same-origin, blob: URLs and data: URLs are allowed so that content generated by JavaScript, such as pictures created in an image-editor Web app, can be downloaded.
  • If the HTTP header Content-Disposition: gives a different filename than this attribute, the HTTP header takes priority over this attribute.
  • If Content-Disposition: is set to inline, Firefox prioritizes Content-Disposition, like the filename case, while Chrome prioritizes the download attribute.

浏览器支持

support_table

Written on 2019-01-11
上篇: Python算法教程学习笔记_第二章
下篇: 海龟绘图入门