最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - "Access is Denied" when attempting to open a URL generated for a procedurally-generated PDF in IE

programmeradmin0浏览0评论

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?

Share Improve this question edited May 2, 2016 at 14:51 Andrew Gray asked May 2, 2016 at 14:29 Andrew GrayAndrew Gray 3,7903 gold badges42 silver badges78 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

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);
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论