I'm getting some odd results when trying to open a new window with a blob url in Windows Edge (20.10240.16384, which is the version in the IE11 VM supplied by Microsoft).
var xhr = new XMLHttpRequest();
xhr.open('POST', sourceUrl, true);
xhr.responseType = 'blob';
xhr.onload = function(e,form) {
if (this.status == 200) {
var blob = this.response;
var url = window.URL.createObjectURL(blob);
var w = window.open(url);
}
}
On the line
var w = window.open(url);
I'm getting an "Access is denied" error which looks to be tied up with CORS ,which makes sense a little as it's not technically the same domain. However a BLOB url doesn't technically have a domain?
Is this a bug in Edge? Or am I doing something not quite right? This code works in IE, Chrome etc.
The Blob object represents a blob, which is a file-like object of immutable, raw data; they can be read as text or binary data, or converted into a ReadableStream so its methods can be used for processing the data. Blobs can represent data that isn't necessarily in a JavaScript-native format.
Blob URL/Object URL is a pseudo protocol to allow Blob and File objects to be used as URL source for things like images, download links for binary data and so forth. For example, you can not hand an Image object raw byte-data as it would not know what to do with it.
The URL. createObjectURL() static method creates a string containing a URL representing the object given in the parameter. The URL lifetime is tied to the document in the window on which it was created. The new object URL represents the specified File object or Blob object.
I found out the solution on both IE and Edge.
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob);
}
else {
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
}
The link Here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With