angularjs - 在 AngularJS 中设置 window.location 或 window.open 在 IE 11 中给出 "access is denied"

标签 angularjs internet-explorer internet-explorer-11

我确实是 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/

相关文章:

coldfusion - 我如何使用 AngularJS 和 serializeJSON cfquery

javascript - 带有 JSON 嵌入数组的 Angularjs 表

angularjs - 使用 REST 进行 Angular http 获取

html - 垂直渐变/IE

asp.net - 在 IE 6 中调整 Div 大小

javascript - 对象作为 React 子对象无效(在 React 15.4.1 的 Internet Explorer 11 中)

javascript - 使用域名时 IE11 权限被拒绝

javascript - 使用 Rails 后端在 Angular 中渲染初始 View

css - <ul> 中向后兼容的逗号列表

javascript - showModalDialog - IE11 忽略对话框高度和对话框宽度