html5下载属性在FF中不起作用 [英] html5 download attribute not working in FF

查看:76
本文介绍了html5下载属性在FF中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个带有下载属性的锚标签,点击后会从href中定义的网址下载图片。这在Chrome中运行良好,但在Firefox中,它会在浏览器中显示图像。我们有什么方法可以在FF工作吗

Hi I have an anchor tag with download attribute which when clicked downloads the image from the url defined in href. This works fine in Chrome but in Firefox it takes to the image in the browser. Is there any way we can make this work in FF

<a href="https://www.ricoh.com/r_dc/r/r8/img/sample_10.jpg" download="JPG">image</a>


推荐答案

这个问题是在Firefox中这只能起作用对于具有相同来源的文件。来自 MDN

The problem with this is that in Firefox this only works for files with the same origin. From MDN:


在Firefox 20中,此属性仅适用于具有相同来源的资源的链接。

In Firefox 20 this attribute is only honored for links to resources with the same-origin.

我看到三个解决方案:


  • 如果你拥有目标图像并控制它,你应该从与您放置链接的页面相同的域。

  • 设置反向代理以通过相同的来源提供图像

  • 再次,如果您拥有目标网站,您可以使用 Content-Type:application / octet-stream 标头来提供它,这将强制浏览器下载图像,无论下载链接的外观如何

  • If you own the target image and has control over it, you should serve it from the same domain as the page where you put the link.
  • Set up a reverse proxy to serve the images through the same origin
  • Again, if you own the target site, you could serve it with a Content-Type: application/octet-stream header which will force the browser to download the image regardless of how the download link looks

这篇关于html5下载属性在FF中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆