[英]“Access is Denied” when attempting to open a URL generated for a procedurally-generated PDF in IE11
For an application I am working on, we have a feature where we are generating a report for an object on the server side, and opening it in a new tab (for the time being) on the client. 对于我正在处理的应用程序,我们有一个功能,我们在服务器端为对象生成报告,并在客户端的新选项卡(暂时)中打开它。
I'm using the URL.createObjectURL
function to make a URL for a Blob
, which is comprised of the results of an AJAX call. 我正在使用URL.createObjectURL
函数为Blob
创建一个URL,它由AJAX调用的结果组成。 Whenever a $window.open(generatedFileUrl)
call is made, however, I recieve a JavaScript error. 但是,无论何时进行$window.open(generatedFileUrl)
调用,我都会收到JavaScript错误。
Controller: 控制器:
(function() {
angular.module('app').controller('someCtrl', [
'$window', 'someSvc', controller
]);
function controller($window, someSvc) {
var vm = this;
vm.thing = {}; // How we get the object is unimportant for this question.
vm.printThing = printThing;
function printThing() {
someSvc.printThing(vm.thing.id, vm.someFlag)
.then(function(result) {
var file = new Blob([result], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
$window.open(fileURL);
});
}
}
)();
Service: 服务:
(function () {
angular.module('app').factory('someSvc', [
'$http', someSvc
]);
function someSvc($http) {
var service = {
printThing: function(thingId, someFlag) {
var args = {
'thingId': thingId,
'someFlag': someFlag
};
return $http.get('/Reports/SomeReport', { 'params': args });
}
};
return service;
}
})();
The server side code is unimportant to this question. 服务器端代码对这个问题并不重要。
Question: Why is it that in my controller code, I get the error message, 0x80070005 - JavaScript runtime error: Access is denied.
问题:为什么在我的控制器代码中,我收到错误消息, 0x80070005 - JavaScript runtime error: Access is denied.
in IE11? 在IE11? Additionally, in what way can I avoid the Access Is Denied error? 此外,我可以以什么方式避免访问被拒绝错误?
IE won't allow you to open blobs directly. IE不允许你直接打开blob。 You have to use msSaveOrOpenBlob
. 你必须使用msSaveOrOpenBlob
。 There's also msSaveBlob
. 还有msSaveBlob
。
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.