我有一个包含图像的移动 html 页面。我想创建一个用于下载图像的按钮或链接。然后应将图像保存到用户的移动图像库中。
我看过这个帖子:How can I create download link in html?
解决方案
<a href="link/to/your/download/file" download="filename">Download link</a>
在桌面浏览器中工作,但在移动设备上不工作。
这是我制作的 JSFiddle:http://jsfiddle.net/tDVqH/4/
注意:图像是在浏览器中创建的,即在 HTML5 canvas 元素中。这个图像可以用 canvas.toDataUrl() 生成。生成的图像应保存到移动图像库中。
如何通过单击/点击将图像保存到用户的移动图像库?是否有没有带有未知 header 的 ser 往返的 JavaScript 解决方案?
编辑:我还发现了以下问题,但没有答案。 Save an image to the local folder from the website by clicking a link or button in mobile browser和 Save an image to a mobile phone gallery from a browser
最佳答案
有人似乎有answered this already ,
<a href="/path/to/image" download="ImageName" title="ImageName"> <img src="/path/to/image" alt="ImageName"> </a> It's not yet fully supported http://caniuse.com/#feat=download, but you can use with modernizr
http://modernizr.com/download/#-a_download (under Non-core detects) to support all browsers.
尚未测试,但应该也适用于手机。
我要补充一点,作为服务器端解决方案,您还可以通过以下方式将响应 header 添加到您的下载端点
- 在 apache (.htaccess)/nginx 配置中设置
- 直接来自代码
关于javascript - 如何在 HTML 中为移动页面创建图像下载链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22338201/