And*_*ray 3 javascript pdf-generation angularjs
对于我正在处理的应用程序,我们有一个功能,我们在服务器端为对象生成报告,并在客户端的新选项卡(暂时)中打开它.
我正在使用该URL.createObjectURL函数为a创建一个URL Blob,该URL 由AJAX调用的结果组成.$window.open(generatedFileUrl)但是,无论何时进行调用,我都会收到JavaScript错误.
控制器:
(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);
});
}
}
)();
Run Code Online (Sandbox Code Playgroud)
服务:
(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;
}
})();
Run Code Online (Sandbox Code Playgroud)
服务器端代码对这个问题并不重要.
问题:为什么在我的控制器代码中,我收到0x80070005 - JavaScript runtime error: Access is denied.IE11中的错误消息?此外,我可以以什么方式避免访问被拒绝错误?
IE不允许你直接打开blob.你必须使用msSaveOrOpenBlob.还有msSaveBlob.
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(blob, fileName);
} else {
var objectUrl = URL.createObjectURL(blob);
window.open(objectUrl);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1694 次 |
| 最近记录: |