admin管理员组文章数量:1416642
How can i display a Blob with pdf content immediately a new tab or have it displayed inline using an iframe?
in chrome and FF i can use something like this
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
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?
or is there a similar solution for the "createObjectURL" that does work for IE?
How can i display a Blob with pdf content immediately a new tab or have it displayed inline using an iframe?
in chrome and FF i can use something like this
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
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?
or is there a similar solution for the "createObjectURL" that does work for IE?
Share Improve this question asked Aug 20, 2015 at 16:25 jstrailjstrail 491 gold badge1 silver badge2 bronze badges 2- 2 I think you'd need to create a temp file on the server to open it in a new window or tab using the browser. To serve a new document your server needs a file to server from, but if you can temporarily cache it on your server you can open the pdf directly in the browser no problem. – DrewT Commented Aug 20, 2015 at 16:33
-
1
According to MDN,
URL.createObjectURL(blob)
is supported in IE10 and up, but OP doesn't mention IE version. – EternalHour Commented Sep 26, 2019 at 20:45
1 Answer
Reset to default 1For security reason and implementation the operation is not allowed in IE so the team build a specific API for asking permissions:
// 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./library/hh673542(v=vs.85).aspx
本文标签: javascriptHow to open a blob object in new windowStack Overflow
版权声明:本文标题:javascript - How to open a blob object in new window - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745252812a2649924.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论