移动Safari下载问题:该操作无法完成. (webkitblobresource错误1.) [英] Mobile Safari download issue : The operation couldn’t be completed. (webkitblobresource error 1.)

查看:1727
本文介绍了移动Safari下载问题:该操作无法完成. (webkitblobresource错误1.)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Angular应用程序具有pdf下载选项.当我在Iphone(IOS 12)Safari浏览器中运行应用程序时,收到以下错误消息,如图所示

My Angular application has a pdf download option. When i run my application in Iphone(IOS 12) Safari browser I get the following error message as shown in the image

我该如何解决?

推荐答案

如果要以编程方式将ancor标记注入DOM中,请确保不要过早清除它.

If you are injecting an ancor tag into DOM programmatically as your solution, make sure you do not clear that up too soon.

对我来说100ms可以正常工作,但是由于无论哪种方式都不可见,我选择清除DOM的延迟时间为1秒.

For me 100ms worked fine but since it's invisible either way I chose 1 second delay on clearing DOM up.

示例代码:

this.fileApi.download(<your args>).subscribe((data: Blob) => {
    const url = window.URL.createObjectURL(data);
    const a = document.createElement('a');
    a.style.display = 'none';
    a.href = url;

    // the filename you want
    a.download = <your filename>;
    document.body.appendChild(a);
    a.click();

    setTimeout(() => {
      window.URL.revokeObjectURL(url);
      document.body.removeChild(a);
    }, 1000);
  })

这篇关于移动Safari下载问题:该操作无法完成. (webkitblobresource错误1.)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆