This question already has an answer here:
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.
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
来源:https://stackoverflow.com/questions/32217537/windows-edge-and-opening-a-blob-url