下载属性与文件名不起作用? [英] Download attribute with a file name not working?
问题描述
下载属性用于使浏览器下载锚点指向的资源,而不是导航到它。作为选项,可以提供下载文件的新文件名。
请注意,并非所有浏览器都支持此功能。请参阅 http://caniuse.com/#feat=download
假设我们有以下链接:
< a href =http:// video -js.zencoder.com/oceans-clip.mp4download =video.mp4>下载< / a>
通过点击链接,我预计会下载名为video.mp4的文件。但实际的文件名是oceans-clip.mp4,用于下载的文件。你知道为什么这里没有使用新的文件名吗?
(我用Chrome测试过)
谢谢!
可与blob:URLs和data:URL一起使用,以便用户轻松下载使用JavaScript以编程方式生成的内容(例如图片使用在线绘图Web应用程序创建。)
如果存在HTTP头Content-Disposition:并且提供与此属性不同的文件名,则HTTP头优先于此属性。
如果此属性存在且Content-Disposition:设置为内联,则Firefox会优先处理Content-Disposition到下载属性。
此属性仅适用于指向同源资源的链接。
这不是来自同一来源,因此它不会起作用。
Download attribute is used to make browsers download the resource an anchor points to rather than navigate to it. And as an option, a new file name for the downloaded file can be provided.
Note that not all browsers support this. See http://caniuse.com/#feat=download
Let's suppose we had the following anchor link:
<a href="http://video-js.zencoder.com/oceans-clip.mp4" download="video.mp4"> download </a>
By clicking the link, I would expect to download the file with the name, video.mp4. But the actual file name, which is oceans-clip.mp4 was used for the downloaded file. Do you know why the new file name was not used here? (I tested this with Chrome)
Thanks!
According to HTML element reference->[a]
Can be used with blob: URLs and data: URLs, to make it easy for users to download content that is generated programmatically using JavaScript (e.g. a picture created using an online drawing Web app).
If the HTTP header Content-Disposition: is present and gives a different filename than this attribute, the HTTP header has priority over this attribute.
If this attribute is present and Content-Disposition: is set to inline, Firefox gives priority to Content-Disposition, like for the filename case, while Chrome gives priority to the download attribute.
This attribute is only honored for links to resources with the same-origin.
It's not from the same-origin, therefore it won't work.
这篇关于下载属性与文件名不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!