iOS从href标签html下载图像 [英] iOS download image from href a tag html
问题描述
我有一些非常简单的东西.
I have something very simple.
我将一个简单的bloburl放在一个标签的href中.
I will put a simple bloburl to a href of an a tag.
<a id="downloadReady" class="btn btn-primary" download=""
href="blob:https://pic2.conveyor.cloud/934d8e82-cfb2-43d4-b0f9-00822621f772">
Download Ready!
</a>
超级简单.
在android,windows,blackberry等系统上均可正常运行.在ios上,点击3次后,我得到以下消息.
On android, windows, blackberry etc it works. On ios i get following message after 3 taps.
This website is repeatedly trying to open another application
允许的图像很大,虽然不是很大,但它来自iPhone相机,在较小的图像上可以使用.
Granted the image is large, not very but it was from iphone camera, on smaller images it works.
由于当前存在错误,因此我无法嵌入jsbin中.也许有人可以帮助我吗?
I cannot embed in jsbin because there is a bug currently. Maybe somebody can help me out?
注意:该代码是在简单的网站,浏览器中使用的,而不是诸如ionic等的本机混合Web应用程序.
Note: the code is used in a simple website, in the browser, not a native hybrid web app like ionic etc.
推荐答案
在使用Chrome浏览器在iOS上下载pdf时,我也面临着完全相同的问题. 我使用fileReader方法来解决此问题.我还添加了此条件,条件是该代码仅适用于iOS上的Chrome. 下面是我的代码
I was also facing exactly the same issue while downloading pdf on iOS using Chrome Browser. I used fileReader approach to fix that. Also I added this under condition that this code should work only for Chrome on iOS. Below is my code
if (window.navigator.userAgent.toLowerCase().indexOf('crios') > -1) {
const fileReader = new FileReader()
const blobUrl = new Blob([serviceResponse.data], { type:
'application/pdf' })
fileReader.onload = function (event) {
window.location.href = reader.result
}
fileReader.readAsDataURL(blobUrl)
}
如果您需要进一步澄清,请告诉我.
Let me know in case you need further clarification.
这篇关于iOS从href标签html下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!