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 prised of the results of an AJAX call. Whenever a $window.open(generatedFileUrl)
call is made, however, I recieve a JavaScript error.
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.
in IE11? Additionally, in what way can I avoid the Access Is Denied error?
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 prised of the results of an AJAX call. Whenever a $window.open(generatedFileUrl)
call is made, however, I recieve a JavaScript error.
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.
in IE11? Additionally, in what way can I avoid the Access Is Denied error?
1 Answer
Reset to default 10IE won't allow you to open blobs directly. You have to use msSaveOrOpenBlob
. There's also msSaveBlob
.
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742399309a4436583.html
评论列表(0条)