首页 > 解决方案 > PDF文件下载在Ipad移动浏览器(chrome和safari)中不起作用 - Angular JS

问题描述

我有一个 Angular JS 应用程序。我正在尝试使用以下代码在移动浏览器上的新选项卡(来自后端)中下载 PDF 文件。

this.windowHolder.windowObjectReference = window.open("about:blank", "_blank");

this.windowHolder.windowObjectReference.location.href = downloadContentUrl;

在哪里,

windowHolder 是 WindowHolder 类的一个实例,如下所示。

class WindowHolder {

    public intervalTimeID: number;
    public intervalCallPopup: number;
    public windowObjectReference: any;

    constructor() {
        this.intervalTimeID = 0;
        this.intervalCallPopup = 0;
        this.windowObjectReference = null;
    }

    public close() {
        if (this.windowObjectReference !== null) {
            this.windowObjectReference.close();
            this.windowObjectReference = null;
        }
    }
}

它在除IPAD之外的所有设备和浏览器中都能正常工作。相同的逻辑在 iphone 移动浏览器(safari 和 chrome)中运行良好。问题仅与 IPAD 浏览器有关。

IPAD chrome 中的问题: PDF 文件已下载,但当我尝试打开时显示文件已损坏或损坏。

IPAD Safari 中的问题:根本无法下载 PDF 文件。而是浏览器显示 WebKitBlobResource 错误

我需要修复此代码,以便即使在 IPAD 浏览器中也能下载 PDF。感谢你的帮助。提前致谢。

标签: angularjspdfipaddownloadmobile-browser

解决方案


推荐阅读