|
1 |
| -area_download.md |
| 1 | +HTML \<area> download 属性 |
2 | 2 | ===
|
3 | 3 |
|
4 |
| -欢迎您编辑 <a target="__blank" href="https://github.com/jaywcjlove/html-tutorial/blob/main/docs/tags/area_download.md">docs/tags/area_download.md</a> 文件,共建 HTML Tutorial 文档。 |
| 4 | +## 示例 |
| 5 | + |
| 6 | +使用 `download` 属性指定当用户单击超链接时将下载目标: |
| 7 | + |
| 8 | +```html idoc:preview |
| 9 | +<img src="https://user-images.githubusercontent.com/1680273/165700877-949e520a-c085-40ce-abd4-2996da31f33b.png" width="145" height="126" alt="Planets" |
| 10 | +usemap="#planetmap"> |
| 11 | + |
| 12 | +<map name="planetmap"> |
| 13 | + <area download shape="rect" coords="0,0,82,126" href="a.html" alt="Sun"> |
| 14 | + <area download shape="circle" coords="90,58,3" href="address.html" alt="Mercury"> |
| 15 | + <area download shape="circle" coords="124,58,8" href="applet.html" alt="Venus"> |
| 16 | +</map> |
| 17 | +``` |
| 18 | + |
| 19 | +## 定义和用法 |
| 20 | + |
| 21 | +`download` 属性指定当用户单击超链接时将下载目标(`href` 属性中指定的文件)。 |
| 22 | + |
| 23 | +`download` 属性的可选值将是文件下载后的新名称。 对允许值没有限制,浏览器会自动检测正确的文件扩展名并将其添加到文件中(`.img`、`.pdf`、`.txt`、`.html` 等)。 |
| 24 | + |
| 25 | +如果省略该值,则使用原始文件名。 |
| 26 | + |
| 27 | +## 浏览器支持 |
| 28 | + |
| 29 | +表中的数字指定了完全支持该属性的第一个浏览器版本。 |
| 30 | + |
| 31 | +| 属性 | ![chrome][1] | ![edge][2] | ![firefox][3] | ![safari][4] | ![opera][5] | |
| 32 | +| ---- | ---- | ---- | ---- | ---- | ---- | |
| 33 | +| download | 14.0\* | 18.0 | 20.0\* | 10.1 | 15.0 | |
| 34 | +<!--rehype:style=width: 100%; display: inline-table;--> |
| 35 | + |
| 36 | +\* Chrome 65+ 和 Firefox 仅支持同源下载链接。 |
| 37 | + |
| 38 | +## 语法 |
| 39 | + |
| 40 | +```html |
| 41 | +<area download="filename"> |
| 42 | +``` |
| 43 | + |
| 44 | +## 属性值 |
| 45 | + |
| 46 | +| 值 Value | 描述 Description | |
| 47 | +| ----- | ----- | |
| 48 | +| *filename* | 可选的。 指定下载文件的新文件名 | |
| 49 | +<!--rehype:style=width: 100%; display: inline-table;--> |
| 50 | + |
| 51 | +## 更多示例 |
| 52 | + |
| 53 | +为下载属性指定一个值,它将是下载文件的新文件名(`sun.html` 而不是 `a.html` 等): |
| 54 | + |
| 55 | +```html idoc:preview |
| 56 | +<img src="https://user-images.githubusercontent.com/1680273/165700877-949e520a-c085-40ce-abd4-2996da31f33b.png" width="145" height="126" alt="Planets" |
| 57 | +usemap="#planetmap"> |
| 58 | + |
| 59 | +<map name="planetmap"> |
| 60 | + <area download="sun" shape="rect" coords="0,0,82,126" href="a.html" alt="Sun"> |
| 61 | + <area download shape="circle" coords="90,58,3" href="address.html" alt="Mercury"> |
| 62 | + <area download shape="circle" coords="124,58,8" href="applet.html" alt="Venus"> |
| 63 | +</map> |
| 64 | +``` |
| 65 | + |
| 66 | +[1]: ../assets/chrome.svg |
| 67 | +[2]: ../assets/edge.svg |
| 68 | +[3]: ../assets/firefox.svg |
| 69 | +[4]: ../assets/safari.svg |
| 70 | +[5]: ../assets/opera.svg |
0 commit comments