Windows Edge and opening a blob url [duplicate]
Asked Answered
O

1

13

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.

Othelia answered 26/8, 2015 at 3:32 Comment(4)
any luck with this one? I'm having errors like this reported on data created on the client itself. My google-fu hasn't uncovered a solution yet...Flashover
I ended up rewriting it to not get use blob urls. So no I haven't uncovered a fix for doing it this way yet.Othelia
old post- But what did u use instead of blob urls?Etty
installing latest version edge (80.x and above) resolves thisBrina
R
15

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

Rodrigues answered 26/5, 2017 at 21:23 Comment(3)
do you know if this will work if IE or Edge has adblock plus or something of the sort that blocks opening popups silently? For non IE i ended up using window.location which does not trigger a new tab. I don't know about IE/Edge if it has a msLoadBlobInCurrentTab so to say...Theodolite
i try your code but not working in Edge.Tumefacient
not working. In IE it is showing access denied exception. I have a blob response object. I have to download that. So creating url like let url = URL.createobjecturl(blob); window.open(url); this is working fine in chrome. But in IE it is not working. So here I had to use msSaveOrOpenBlob. Here file is getting downloaded but it is not able to open automatically in a new tab like chrome. So is there any way to achieve it in Edge. @ Irvin DomininPresentment

© 2022 - 2024 — McMap. All rights reserved.