关于 Safari 无法下载 pdf 文件的问题

测试了很长时间,使用了各种方法,后来在一开源下载工具FileSaver.js的讨论中了解到苹果这边目前暂不支持

相关讨论帖

有用的讨论信息

No there is no alternative package if there where we would have fixed it already and the question have brought up many times.
So there is nothing we can do except to wait for ios to fix it
and since there is nothing to do i will close this.

But still, it does not show or popup the Download File dialog on IOS 11.4. I tried Safari, Chrome, and Firefox and all behaves in the same way. All the 3 browsers open the text file content in a new tab generating some weird filename which is visible on the tab title bar as well as in the URL bar.
Any idea of how can I popup a download file dialog to save the Text file in IOS? I am using AngularJS for my App Development.

So the conclusion here about safari is

  1. download attribute in safari is not supported
  2. It will try other means to save the blob by opening a new url
  3. If the mimetype can be rendered by safari it will be able to display it in a new tab
  4. If the mimetype is application/octet-stream:
    4.1 Create a base64 link with FileReader api
    4.2 try to open a new tab using window.open + base64 url
    4.3 if it was more then 1 sec before the user interaction happened it will use the current page instead
    but that is likely going to fail because (see first example using location.href) Failed to load resource: Frame load interrupted This may still work if the mimetype is not application/octet-stream and the saveAs was not called synchronous
  5. Safari don’t have anything like msSaveAs()
  6. safest way to force the file to be saved is to have a data:attachment/file" + base64 ready and open that link using window.open() when the user interacts with the website (or at least to it under 1 second)
  7. when saving it as a attachment filename will be “unknown”

I suppose that the opening in new tab is expected behavior for Safari <12 on iOS because the browsers do not have an access to file system. This gives the user a chance to save a file with an additional click to the cloud storage.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wang's Blog

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值