javascript - 如何在新窗口中打开 blob 对象

标签 javascript jquery url blob src

我如何立即在新选项卡中显示带有 pdf 内容的 Blob 或使用 iframe 将其内联显示?

在 chrome 和 FF 中我可以使用这样的东西

var url = URL.createObjectURL(blob);
$('#uplFrame').attr('src', url);

但在 IE 中不起作用...我在网上看到 IE 正在使用以下内容处理 blob

window.navigator.msSaveOrOpenBlob(blob, "filename");

但是这会询问用户是否要在新窗口中保存或打开文件。是否可以让代码自动打开 blob?

或者是否有适用于 IE 的“createObjectURL”的类似解决方案?

最佳答案

出于安全原因和实现,该操作在 IE 中是不允许的,因此团队构建了一个特定的 API 来请求权限:

  // Save the blob1 content to a file, giving just a "Save" option
  window.navigator.msSaveBlob(blob1, 'msSaveBlob_testFile.txt'); 

  // Save the blob2 content to a file, giving both "Save" *and* "Open" options
  window.navigator.msSaveOrOpenBlob(blob2, 'msSaveBlobOrOpenBlob_testFile.txt');

引用:https://msdn.microsoft.com/library/hh673542(v=vs.85).aspx

关于javascript - 如何在新窗口中打开 blob 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32123509/

相关文章:

JavaScript 创建 zip 文件

jQuery 单击前 x 个按钮

java - 从请求 URL 中检索值

c# - 使用 http :\\URL 的 WPF 图像 UriSource 和数据绑定(bind)

javascript - 简单的 Javascript 字符串操作

javascript - 从 ExtJS 中的 Store 访问数据?

JavaScript 重定向 : Problem with Referer Header

javascript 在空格时分割但并非总是如此

javascript - jQuery Mobile 导航选项卡

python - 在 Django 中填充 URLFields 的合法值的确切模式是什么?