我确实是 AngularJS 新手,但我不明白为什么这段代码可以在 Chrome 和 Firefox 中工作,但在 IE 11 的 javascript 控制台中给出“访问被拒绝”
。
我需要通过经过身份验证的 REST 调用显示 PDF。理想情况下,这将显示在弹出(预览)类型的窗口中。
到目前为止的代码如下:
$http.post( url, payload, {
headers : {
"Authorization": token
},
responseType: "arraybuffer"
}).success(function ( data ) {
var file = new Blob( [ data ], { type: 'application/pdf' });
var fileURL = URL.createObjectURL( file );
window.open( fileURL );
}
对于 IE11,window.open()
给出“访问被拒绝”
消息,但适用于 Chrome 和 Firefox。我尝试更改为 window.location()
,但得到了相同的错误。
这不是跨域问题(所有内容都在同一个 foo.net 域中)。
最佳答案
Saving text in a local file in Internet Explorer 10
看起来 IE 会阻止 blob 上的 window.open,但实现了自己的打开和保存 blob 的功能。相反尝试
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob);
}
else {
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
}
关于angularjs - 在 AngularJS 中设置 window.location 或 window.open 在 IE 11 中给出 "access is denied",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27463901/