Windows Edge并打开一个blob网址 [英] Windows Edge and opening a blob url
问题描述
尝试在Windows Edge(20.10240.16384,这是Microsoft提供的IE11 VM中的版本)中使用blob url打开一个新窗口时,我得到了一些奇怪的结果。
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);
}
}
在线
var w = window.open(url);
我收到访问被拒绝错误,该错误似乎与CORS捆绑在一起因为它在技术上不是同一个域,所以有点意义。但是BLOB网址在技术上没有域?
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?
这是Edge中的错误吗?或者我做的事情不太对劲?此代码适用于IE,Chrome等。
Is this a bug in Edge? Or am I doing something not quite right? This code works in IE, Chrome etc.
推荐答案
我在IE和Edge上找到了解决方案。
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);
}
链接 Here
这篇关于Windows Edge并打开一个blob网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!