Windows Edge and opening a blob url [duplicate]

守給你的承諾、 提交于 2019-12-18 13:16:24

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!