Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

html - Download attribute with a file name not working?

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...