Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting window.location or window.open in AngularJS gives "access is denied" in IE 11

I'm admittedly an AngularJS newbie but I can't find why this code works in Chrome and Firefox but gives "Access is denied" in the javascript console with IE 11.

I need to display a PDF via an authenticated REST call. Ideally this would be displayed in a popup (preview) kind of window.

Code thus far looks like:

$http.post( url, payload, {
    headers : {
        "Authorization": token
    }, 
    responseType: "arraybuffer"
}).success(function ( data ) {
    var file = new Blob( [ data ], { type: 'application/pdf' });
    var fileURL = URL.createObjectURL( file );
    window.open( fileURL );
}

The window.open() gives the "access is denied" message for IE11, but works in Chrome and Firefox. I tried changing to window.location(), and got the same error.

This isn't a cross-domain issue (everything is in the same foo.net domain).

like image 304
Matt Avatar asked Dec 13 '14 21:12

Matt


1 Answers

Saving text in a local file in Internet Explorer 10

It looks like IE blocks window.open on blobs, but implemented their own functions for opening and saving blobs. Instead try

if (window.navigator && window.navigator.msSaveOrOpenBlob) {
    window.navigator.msSaveOrOpenBlob(blob);
}
else {
    var objectUrl = URL.createObjectURL(blob);
    window.open(objectUrl);
}
like image 95
Elizabeth Kilson Avatar answered Nov 07 '22 17:11

Elizabeth Kilson