Html Chrome 下载属性不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23872902/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Chrome Download Attribute not working
提问by Buffer Overflow
I've experienced some unexpected behavior of Chrome since the newest version: While in Firefox this Code is working Perfectly fine:
自最新版本以来,我遇到了 Chrome 的一些意外行为:虽然在 Firefox 中,此代码运行良好:
<a id="playlist" class="button" download="Name.xspf" href="data:application/octet-stream;base64,PD94ANDSOON" style="display: inline;">Download Me</a>
It isn't working in Chrome (Simply downloading a file named "Download"), but has worked pretty fine before. What do I have to change that it is working again?
它在 Chrome 中不起作用(只需下载一个名为“下载”的文件),但以前工作得很好。我必须改变什么才能让它再次工作?
回答by Augustin Riedinger
Reading the comments, I had the same issue as @buffer-overflow and found this in the issue:
阅读评论,我遇到了与@buffer-overflow 相同的问题,并在问题中发现了这一点:
I'm guessing that the web page and the download are on different origins. We no longer honor the download attribute suggested filename for cross origin requests. Clicking on the link still initiates a download. But the the filename is only derived from factors solely dependent on the server (e.g. Content-Disposition header in the response and the URL).
我猜网页和下载的来源不同。我们不再尊重跨源请求的下载属性建议文件名。单击链接仍会启动下载。但是文件名仅源自完全依赖于服务器的因素(例如响应中的 Content-Disposition 标头和 URL)。
So no chance I could make it work ... :(
所以我没有机会让它工作...... :(
回答by Emanuel Vintil?
After some research I have finally found your problem.
经过一番研究,我终于找到了你的问题。
<a> download attribute:
<a> 下载属性:
If the HTTP header Content-Disposition: is present and gives a different filename than this attribute, the HTTP header has priority over this attribute.
如果 HTTP 标头 Content-Disposition: 存在并给出与此属性不同的文件名,则 HTTP 标头优先于此属性。
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.
如果此属性存在且 Content-Disposition: 设置为 inline,则 Firefox 优先考虑 Content-Disposition,就像文件名大小写一样,而 Chrome 优先考虑下载属性。
HTTP-Header Content-Disposition
HTTP-Header Content-Disposition
回答by AKSHAYA KUMAR Satapathy
I have a simple solution regarding this issue. You just need to put your html file into a server like Apache using xampp control and so on. Because the download attribute is properly working through a server.
关于这个问题,我有一个简单的解决方案。您只需要使用 xampp 控件等将 html 文件放入像 Apache 这样的服务器中。因为下载属性通过服务器正常工作。
<a download href="data:application/octet-stream;base64,PD94ANDSOON">Download Me</a>
回答by venkata krishna sharma
This can be resolved by adding target="_blank"
attribute to the href
.
这可以通过添加解决target="_blank"
属性的href
。
Like this:
像这样:
Save sprites.svg as
<a target="_blank" download="somefilename.svg"
href="https://cdn.sstatic.net/Img/unified/sprites.svg"
>somefilename.svg</a>
回答by ankit
Go To Chrome Click on “Settings” and you'll see a new page pop up in your Chrome browser window. Scroll down to Advanced Settings, find the Downloads group, and clear your Auto Open options. Next time you download an item, it will be saved instead of opened automatically.
转到 Chrome 单击“设置”,您会在 Chrome 浏览器窗口中看到一个新页面弹出。向下滚动到“高级设置”,找到“下载”组,然后清除“自动打开”选项。下次下载项目时,它将被保存而不是自动打开。