下载属性在Chrome上不起作用

时间:2019-05-09 17:30:57

标签: javascript html image

我正在尝试使用download属性,它在Firefox上可以使用,但是当我在Chrome中运行相同的HTML文件时,则无法使用。

这是我的html文件:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Download</title>
  </head>
  <body>

      <a download="mylogo" href="san-francisco.jpg"><img src="san-francisco.jpg" alt="Photo" width="104" height="142"></a>

  </body>
</html>

1 个答案:

答案 0 :(得分:2)

尝试一下:

<a target="_blank" download="mylogo" href="san-francisco.jpg" title="ImageName">
    <img alt="ImageName" src="san-francisco.jpg" width="104" height="142">
</a>

如果不是这个目的:

下载属性:

如果HTTP标头Content-Disposition:存在并且提供的文件名与此属性不同,则HTTP标头优先于该属性。

如果此属性存在并且Content-Disposition:设置为inline,则Firefox优先考虑Content-Disposition,例如文件名,而Chrome优先考虑download属性。

Source

HTTP标头Content-Disposition

相关问题