【问题标题】:iOS download image from href a tag htmliOS从href a标签html下载图片
【发布时间】:2018-04-01 18:37:24
【问题描述】:

我有一些非常简单的事情。

我会将一个简单的 bloburl 放在 a 标签的 href 中。

<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 次后收到以下消息。

This website is repeatedly trying to open another application

虽然图像很大,但不是很大,但它来自 iphone 相机,在较小的图像上它可以工作。

我无法嵌入 jsbin,因为目前存在错误。也许有人可以帮助我?

注意:代码用于一个简单的网站,在浏览器中,而不是像 ionic 等原生混合网络应用程序。

【问题讨论】:

  • Granted the image is large - 可能要等一段时间看看下载是否需要时间
  • 安卓即时,ios反弹窗系统

标签: javascript ios iphone html hybrid-mobile-app


【解决方案1】:

我在 iOS 上使用 Chrome 浏览器下载 pdf 时也遇到了完全相同的问题。 我使用 fileReader 方法来解决这个问题。此外,我在此代码仅适用于 iOS 上的 Chrome 的条件下添加了此内容。 下面是我的代码

 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)
    }

如果您需要进一步说明,请告诉我。

【讨论】:

  • 上面的代码不是“下载图片”,而是在另一个标签页中打开它。
猜你喜欢
  • 2019-06-03
  • 1970-01-01
  • 2019-10-17
  • 1970-01-01
  • 1970-01-01
  • 2014-05-12
  • 2010-10-27
  • 2021-03-03
  • 2016-01-17
相关资源
最近更新 更多