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/

相关文章:

javascript - 如何在模型窗口angularjs中传递routeparams值?

angularjs - 如何向 AngularUI 日历添加图标

javascript - 一本书中建议了何时使用工厂以及何时使用服务 - 计数器方法

Javascript for..in 和 jQuery 的 $.for() 不适用于 IE 中的 XMLHttpRequest

internet-explorer - IE11 上的 Selenium WebDriver

angular - 在 IE11 和 Edge 中的 Bootstrap 模态上渲染 Artifact

javascript - 包含 ngResource 后,config(function ($resource) {...}) 中的未知提供者 $resource?

html - 下拉导航菜单无法与 ie 一起正常工作

html - 什么会导致 IE9 无法解释或忽略网页的某些部分?

javascript - htmlEle.fireEvent ("onclick"、 document.createEventObject()) 在 IE 11 上不起作用