我如何立即在新选项卡中显示带有 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/