【问题标题】:Save or open blob with FileSaver.js on iOS Chrome and Safari在 iOS Chrome 和 Safari 上使用 FileSaver.js 保存或打开 blob
【发布时间】:2015-09-01 13:41:42
【问题描述】:

我使用 docxtemplater 库从 javascript 创建一个 docx 文档。

在桌面浏览器上,它运行良好。 在移动设备上,在 Android 上没有问题,但我在 iOS 上遇到了一些问题。

在 iOS 上,当我尝试下载或打开文档时,当我可以看到以下类型的 URL 时,会在浏览器中创建一个新选项卡:

blob:http://mylocalServer/987788-3524-33iuhih3334434434

在这个新标签中,我看不到该文档,也无法下载它。

iOS下如何获取docx文档?

下面是用JS创建docx文档的代码:

out=doc.getZip().generate({type:"blob"});
// Give a name for the output word document
var outputName = "test.docx" ;
saveAs(out,outputName);

saveAs 函数在FileSaver.js 文件中被调用:

当这个动作在 iOS 上完成时,我们会抛出这个代码:

fs_error = function() {
// don't create more object URLs than needed
if (blob_changed || !object_url) {
    object_url = get_URL().createObjectURL(blob);
}
if (target_view) {
    target_view.location.href = object_url;
} else {
    var new_tab = view.open(object_url, "_blank");
    if (new_tab == undefined && typeof safari !== "undefined") {
        //Apple do not allow window.open, see http://bit.ly/1kZffRI
        view.location.href = object_url
    }
}
filesaver.readyState = filesaver.DONE;
dispatch_all();
revoke(object_url);
}

【问题讨论】:

    标签: javascript ios google-chrome blob


    【解决方案1】:

    Blob 类型应设置为 application/vnd.openxmlformats-officedocument.wordprocessingml.document,以便 iOS 11 及更高版本 上的 Safari 可以显示文档,用户可以手动下载。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多