0

The code below is for downloading a file in PDF form. The code is working fine for all platforms and devices except iPad's Safari Browser. What are the changes I can make to make it work?

const fileWindow = window.open();
const linkSource = `data:${mimeType};base64,${response.base64}`;
fileWindow.document.write(
  '<title>Visualisation</title>' +
  '<body style="overflow: hidden; margin: 0">' +
  '<object width="100%" width="-webkit-fill-available" height="100%" height="-webkit-fill-available" type="application/pdf" data="' + encodeURI(linkSource) + '"></object>' +
  '</body>'
);
const downloadLink = document.createElement("a");
document.body.appendChild(downloadLink);

downloadLink.href = linkSource;
downloadLink.download = fileName;
downloadLink.click();
  • Apart from the dupes, you are missing `fileWindow.document.close();` before the const download link. also your filename creation is inefficient: `let fileName = this.tabMapping[this.selectedTab] + "." + this.selectedDownloadFormat; const label3 = this.getFieldValue(this._searchLabel3), label4 = this.getFieldValue(this._searchLabel4), radioText = this.selectedRadioOptionText; if (radioText === label3) fileName = label3; else if (radioText === label4) fileName = label4` – mplungjan Jan 20 '23 at 08:04

0 Answers0