简体   繁体   English

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

[英]How to open a blob object in new window

How can i display a Blob with pdf content immediately a new tab or have it displayed inline using an iframe?如何在新标签页中立即显示带有 pdf 内容的 Blob 或使用 iframe 内联显示它?

in chrome and FF i can use something like this在 chrome 和 FF 我可以使用这样的东西

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

but does not work in IE...i read online that IE is using the following for handeling blobs但在 IE 中不起作用...我在网上读到 IE 正在使用以下内容处理 blob

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

however this will ask the user if he wants to save or open the file in a new window.但是,这将询问用户是否要在新窗口中保存或打开文件。 is it possible to let the code open the blob this automatically?是否可以让代码自动打开 blob?

or is there a similar solution for the "createObjectURL" that does work for IE?或者是否有适用于 IE 的“createObjectURL”的类似解决方案?

For security reason and implementation the operation is not allowed in IE so the team build a specific API for asking permissions:出于安全原因和实现,该操作在 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');

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM