Safari 12无法下载PDF blob [英] Safari 12 Won't Download a PDF blob

查看:369
本文介绍了Safari 12无法下载PDF blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码用于通过blob下载pdf。它适用于除Safari 12之外的所有浏览器,适用于macOS和iOS。甚至Safari 11也可以。当我第一次运行代码时,它运行正常,但每次之后它都会给我WebKitBlobResource错误1

This code is used to download a pdf via blob. It works fine on every browser except Safari 12 for macOS and iOS. Even Safari 11 works. When I run the code the very first time, it works fine, but every time after that it gives me "WebKitBlobResource error 1"

function downloadFileFromBlob(fileBlob, fileName) {
    if (/\bMSIE\b|\bTrident\b/.test($window.navigator.userAgent)) {
        $window.navigator.msSaveOrOpenBlob(fileBlob, fileName);
    } else {
        var fileURL = $window.URL.createObjectURL(fileBlob);
        createDownloadElementAndClick(fileURL, fileName);
    }
}

function createDownloadElementAndClick(fileURL, fileName) {
    var anchorElement = $window.document.createElement('a');
    anchorElement.href = fileURL;
    anchorElement.target = '_blank';
    anchorElement.download = fileName;
    var event = $window.document.createEvent("MouseEvents");
    event.initEvent("click", true, false);
    anchorElement.dispatchEvent(event);
}

推荐答案

似乎 target =_ blank无法正常工作。我用 _self 替换了它,这显然解决了这个问题。当我遇到同样的问题时,我发现了这一点。

It seems that it is the target = "_blank" that is not working. I have replaced it with _self, which apparently solved the problem. I found this when I had the same issue.

如果有人知道我们为什么不能使用 _blank 我很想听到这个。

If someone has a idea on why we cannot use _blank I would love to hear that.

这篇关于Safari 12无法下载PDF blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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