download 属性は、ユーザがハイパーリンクをクリックしたときに、ダウンロードするターゲットを指定します。
この属性は、href 属性が設定されている場合にのみ使用します。
属性の値は、ダウンロードしたファイルの名前です。許容値には制限がなく、ブラウザが自動的に正しくファイル拡張子を検出して、 ファイルに拡張子(.img、.pdf、.txt、.html など)を追加します。
値を省略した場合は、元のファイル名が使用されます。
download 属性は、以下の要素で使用することができます:
要素 | 属性 |
---|---|
<a> | download |
<area> | download |
リンクをクリックしたときに(ファイルにナビゲートする代わりに)、ファイルをダウンロードします:
<a href="/images/myw3schoolsimage.jpg" download>
Try it Yourself ❯
クリックしたときにダウンロードされる、クリック可能な領域を持つイメージマップ:
<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">
<map name="planetmap">
<area shape="rect" coords="0,0,82,126"
alt="Sun" href="info_about_the_sun.htm" download="sun">
<area
shape="circle" coords="90,58,3" alt="Mercury" href="merglobe.gif" download="mercury">
<area shape="circle" coords="124,58,8" alt="Venus" href="information_about_the_planet_venus.txt"
download="venus">
</map>
Try it Yourself ❯
download
属性は、要素ごとに以下のブラウザがサポートしています。
要素 | |||||
---|---|---|---|---|---|
a | 14.0 | 13.0 | 20.0 | サポートなし | 15.0 |
area | 14.0 | サポートなし | 20.0 | サポートなし | 15.0 |