【问题标题】:Set the file name and open blob pdf type in new tab [duplicate]设置文件名并在新选项卡中打开blob pdf类型[重复]
【发布时间】:2016-07-13 01:55:58
【问题描述】:

我正在尝试在浏览器的新选项卡中打开 blob 字节流。它是有效的,但我不确定如何设置文件名,以便每个文档在下载时都具有唯一的名称。现在,该文档在保存时默认为“document.pdf”。

var blob = new Blob([response.data], { type: "application/pdf" });
            if (blob) {
                var fileURL = window.URL.createObjectURL(blob);
                window.open(fileURL);
            }

【问题讨论】:

标签: javascript pdf


【解决方案1】:

使用window.open 调用给它一个文件名:

window.open(fileURL, "your filename.extension");

如果您使用的是 IE,请改用navigator.msSaveOrOpenBlob

navigator.msSaveOrOpenBlob(fileURL, "your filename.extension");

【讨论】:

  • 在IE中无法打开新标签,只能下载
  • 没有。它忽略“你的文件名.extension”
猜你喜欢
  • 2017-02-01
  • 2019-04-14
  • 2019-04-12
  • 2017-09-18
  • 1970-01-01
  • 2017-08-06
  • 2020-03-02
  • 2020-10-09
  • 2018-11-28
相关资源
最近更新 更多