在 AngularJS 中设置 window.location 或 window.open 会导致“访问被拒绝"在 IE 11 [英] Setting window.location or window.open in AngularJS gives "access is denied" in IE 11

查看:66
本文介绍了在 AngularJS 中设置 window.location 或 window.open 会导致“访问被拒绝"在 IE 11的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实是一个 AngularJS 新手,但我不知道为什么这段代码可以在 Chrome 和 Firefox 中工作,但是在 IE 11 的 javascript 控制台中给出了 访问被拒绝".

I'm admittedly an AngularJS newbie but I can't find why this code works in Chrome and Firefox but gives "Access is denied" in the javascript console with IE 11.

我需要通过经过身份验证的 REST 调用显示 PDF.理想情况下,这将显示在弹出(预览)类型的窗口中.

I need to display a PDF via an authenticated REST call. Ideally this would be displayed in a popup (preview) kind of window.

到目前为止的代码看起来像:

Code thus far looks like:

$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 提供 访问被拒绝" 消息,但适用于 Chrome 和 Firefox.我尝试更改为 window.location(),并得到相同的错误.

The window.open() gives the "access is denied" message for IE11, but works in Chrome and Firefox. I tried changing to window.location(), and got the same error.

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

This isn't a cross-domain issue (everything is in the same foo.net domain).

推荐答案

在 Internet Explorer 10 中将文本保存到本地文件

它看起来像 IE 在 blob 上阻止 window.open,但实现了自己的打开和保存 blob 的功能.而是尝试

It looks like IE blocks window.open on blobs, but implemented their own functions for opening and saving blobs. Instead try

if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    window.navigator.msSaveOrOpenBlob(blob);
}
else {
    var objectUrl = URL.createObjectURL(blob);
    window.open(objectUrl);
}

这篇关于在 AngularJS 中设置 window.location 或 window.open 会导致“访问被拒绝"在 IE 11的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆