如何在HTML中为移动页面创建图像下载链接?
I have a mobile html page which contains images. I want to create a button or a link which is used for a download of an image. The image should then be saved to the users mobile image gallery.
我有一个包含图像的移动html页面。我想创建一个用于下载图像的按钮或链接。然后应将图像保存到用户移动图像库。
I have seen this post: How can I create download link in html?
我看过这篇文章:如何在html中创建下载链接?
The solution
<a href="link/to/your/download/file" download="filename">Download link</a>
is working in desktop browsers but not on mobile.
正在桌面浏览器中工作但不在移动设备上。
Here is a JSFiddle I made: http://jsfiddle.net/tDVqH/4/
这是我制作的JSFiddle:http://jsfiddle.net/tDVqH/4/
Note: The image is created in the browser i.e., in a HTML5 canvas element. This image can be generated with canvas.toDataUrl(). The resulting image should be saved to the mobile image gallery.
注意:图像是在浏览器中创建的,即在HTML5 canvas元素中创建的。可以使用canvas.toDataUrl()生成此图像。生成的图像应保存到移动图像库中。
How can save an image to the users mobile image gallery with a click/tap? Is there a JavaScript solution without the ser round trip with a unknown header?
如何通过点击/点按将图像保存到用户移动图库?是否有一个没有带有未知标题的ser往返的JavaScript解决方案?
Edit: I also found the following questions but they do not have an answer. Save an image to the local folder from the website by clicking a link or button in mobile browser and Save an image to a mobile phone gallery from a browser
编辑:我也发现了以下问题,但他们没有答案。通过单击移动浏览器中的链接或按钮并从浏览器将图像保存到手机库,将图像从网站保存到本地文件夹
4 个解决方案
#1
4
Somebody seems to have 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.
http://modernizr.com/download/#-a_download(在非核心检测下)支持所有浏览器。
Have not tested, but should work in mobiles as well.
尚未测试过,但也应该在手机中使用。
I would add that, as a server side solution, you could also add Response Headers to your download endpoint by
我想补充一点,作为服务器端解决方案,您还可以通过以下方式将响应标头添加到下载端点
- Setting it up in apache (.htaccess) / nginx configuration
- Right from the code
在apache(.htaccess)/ nginx配置中进行设置
从代码开始
更多相关文章
- AngularJS使用双向数据绑定将img元素标签中的图像显示为源?
- 图像未加载到HTML页面的jQuery load()中
- 为什么v-align中的将文本放在图像下面
- html2canvas 识别 svg 解决方案
- 获取图像特定区域的所有多边形坐标?
- 如何在网站中找到未使用的图像和CSS样式?
- 如何在CSS中添加旋转图像?
- 如何在离子框架中显示图像标题?
- HTML5用户身份认证源代码:注册、登录、会话保持的解决方案