"访问被拒绝"试图打开在IE11程序上生成的PDF生成的URL时, [英] "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.
我使用了 URL.createObjectURL
功能,使为的Blob
,这是由一个网址AJAX调用的结果。每当 $ window.open(generatedFileUrl)
调用时,不过,我收到一个JavaScript错误。
I'm using the URL.createObjectURL
function to make a URL for a Blob
, which is comprised of the results of an AJAX call. Whenever a $window.open(generatedFileUrl)
call is made, however, I recieve a JavaScript error.
控制器:
(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);
});
}
}
)();
服务:
(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;
}
})();
在服务器端code是不重要了这个问题。
The server side code is unimportant to this question.
问:为什么在我的控制器code,我得到错误信息, 0X80070005 - JavaScript的运行时错误:访问被拒绝
在IE11?此外,以什么方式我能避免访问被拒绝的错误?
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?
推荐答案
IE不会让你直接打开斑点。你必须使用 msSaveOrOpenBlob
。还有 msSaveBlob
。
IE 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);
}
这篇关于"访问被拒绝"试图打开在IE11程序上生成的PDF生成的URL时,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!