Nils-o-mat Nils-o-mat - 7 months ago 91
jQuery Question

Permission denied for clicking link in Internet Explorer 11

I modified an existing AngularJS-App, which lists customers, by adding a button, that allows to download the customer information as a vcard. I create the vcard in Javascript directly on click. The download-button calls the following function on click with the customer-item as argument:

function transcodeToAnsi(content){
var encoding = "windows-1252";
var nonstandard = {NONSTANDARD_allowLegacyEncoding: true};
return new TextEncoder(encoding, nonstandard).encode(content);

$ = function(item) {
var filename = 'contact.vcf';
var aId = "vcard";

var content = createVCard(item);
var encoded = transcodeToAnsi(content);

var blob = new Blob([ encoded ], { type : 'vcf' });
var url = (window.URL || window.webkitURL).createObjectURL(blob);

$("body").append('<a id="' + aId + '" href="' + url + '" download=' + filename + ' class="hidden"></a>');
$("#" + aId).remove();

return false;

In the createVCard-function I just create the file content as a String, so it should not enter into the problem. The transcoding is done by this library:

The function works without problem in Firefox and Chrome, but not in IE11. The following error is given in the console:

Error: Permission denied
at Anonymous function (http://***/Contacts2015/js/contacts.js:169:9)
at Anonymous function (http://***/static/9bojdXAkdR8XdVMdSTxZAgzEwGWhHMwgpuONdU2Y8F4.js:14305:11)
at completeOutstandingRequest (http://***/static/9bojdXAkdR8XdVMdSTxZAgzEwGWhHMwgpuONdU2Y8F4.js:4397:7)
at Anonymous function (http://***/static/9bojdXAkdR8XdVMdSTxZAgzEwGWhHMwgpuONdU2Y8F4.js:4705:7) undefined

Line 169 is this instruction of the function above:


The same error is displayed, when this statement is input in the console manually.

I would appreciate every hint about the reason and even more a good workaround.


Corrected error-line and typo.


You cannot directly open blobs in Microsoft IE. You must use window.navigator.msSaveOrOpenBlob. There's also msSaveBlob if that's what you need.

$ = function() {
    //etc... logic...
    var blob = new Blob([encoded], {type: 'vcf'});

    //for microsoft IE
    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
        window.navigator.msSaveOrOpenBlob(blob, fileName);
    } else { //other browsers
        var a = document.createElement('a'); = "display:none";
        a.href = URL.createObjectURL(blob); = "filename.jpg";;

One last thing: the previous code won't work on firefox because firefox doesn't support click(). You can prototype its behavior using this snippet: = function() {
   var evt = this.ownerDocument.createEvent('MouseEvents');
   evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);