【问题标题】:Setting window.location or window.open in AngularJS gives "access is denied" in IE 11在 AngularJS 中设置 window.location 或 window.open 在 IE 11 中给出“访问被拒绝”
【发布时间】:2015-02-12 08:38:23
【问题描述】:

诚然,我是 AngularJS 新手,但我不明白为什么这段代码可以在 Chrome 和 Firefox 中运行,但在 IE 11 的 javascript 控制台中提供 "Access is denied"

我需要通过经过身份验证的 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 );
}

window.open() 为 IE11 提供 "access is denied" 消息,但适用于 Chrome 和 Firefox。我尝试更改为window.location(),并得到同样的错误。

这不是跨域问题(所有内容都在同一个 foo.net 域中)。

【问题讨论】:

标签: angularjs internet-explorer internet-explorer-11


【解决方案1】:

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);
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多