iOS download image from href a tag html

依然范特西╮ 提交于 2019-12-24 10:32:55

问题


I have something very simple.

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>

Super simple.

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

Granted the image is large, not very but it was from iphone camera, on smaller images it works.

I cannot embed in jsbin because there is a bug currently. Maybe somebody can help me out?

Note: the code is used in a simple website, in the browser, not a native hybrid web app like ionic etc.


回答1:


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.



来源:https://stackoverflow.com/questions/49601384/ios-download-image-from-href-a-tag-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!