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

jst*_*ail 5 javascript url jquery blob src

如何在新标签页中立即显示带有 pdf 内容的 Blob 或使用 iframe 内联显示它?

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

var url = URL.createObjectURL(blob);
$('#uplFrame').attr('src', url);
Run Code Online (Sandbox Code Playgroud)

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

window.navigator.msSaveOrOpenBlob(blob, "filename");
Run Code Online (Sandbox Code Playgroud)

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

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

Irv*_*nin 1

出于安全原因和实施原因,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');
Run Code Online (Sandbox Code Playgroud)

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

  • 那么只在新选项卡中打开文件怎么样? (2认同)