1

I am using the following function for downloading an attachment file, as binary data, inside an Office 365 app:

var saveByteArray = function (data, name) {
    var a = document.createElement("a");
    document.body.appendChild(a);
    a.style = "display: none";
    var blob = new Blob(data, { type: "octet/stream" }),
    url = window.URL.createObjectURL(blob);
    a.href = url;
    a.download = name;
    a.click();
    window.URL.revokeObjectURL(url);
};

It works successfully in Chrome browser, but following error has occurred, when I open it through the Outlook desktop client:

Error TypeError: Assignment to read-only properties is not allowed in strict mode

The error happens, when executing this line:

access a.style = "display: none";

Is there any alternative solution for this implementation ?

meskobalazs
  • 15,741
  • 2
  • 40
  • 63
DevÁsith
  • 1,072
  • 12
  • 38

1 Answers1

1

You should use #setAttribute instead:

a.setAttribute('style', 'display: none');

I also recommend to use it when setting the other attributes of the a element.

meskobalazs
  • 15,741
  • 2
  • 40
  • 63