How to open a blob object in new window

jstrail picture jstrail · Aug 20, 2015 · Viewed 10.8k times · Source

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?

Answer

Irvin Dominin picture Irvin Dominin · Aug 20, 2015

For 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.com/library/hh673542(v=vs.85).aspx