Skip to content

Commit c25bff5

Browse files
committed
Change base64 handling for IE11
IE11 doesn't support fetch() so we have to go old-school with xhr. Can't wait to drop IE11.
1 parent b7ecaba commit c25bff5

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

pdfobject.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,33 @@
216216

217217
let convertBase64ToDownloadableLink = function (b64, filename, targetNode, fallbackHTML) {
218218

219-
fetch(b64).then(response => response.blob()).then(blob => {
220-
let link = document.createElement('a');
221-
link.innerText = "Download PDF";
222-
link.href = URL.createObjectURL(blob);
223-
link.download = filename;
224-
targetNode.innerHTML = fallbackHTML.replace(/\[pdflink\]/g, link.outerHTML);
225-
});
226-
227-
}
219+
//IE-11 safe version. More verbose than modern fetch()
220+
if (window.Blob && window.URL && window.URL.createObjectURL) {
221+
222+
var xhr = new XMLHttpRequest();
223+
xhr.open('GET', b64, true);
224+
xhr.responseType = 'blob';
225+
xhr.onload = function() {
226+
227+
if (xhr.status === 200) {
228+
229+
var blob = xhr.response;
230+
var link = document.createElement('a');
231+
link.innerText = "Download PDF";
232+
link.href = URL.createObjectURL(blob);
233+
link.setAttribute('download', filename);
234+
targetNode.innerHTML = fallbackHTML.replace(/\[pdflink\]/g, link.outerHTML);
235+
236+
}
237+
238+
};
239+
240+
xhr.send();
241+
242+
}
243+
244+
};
245+
228246

229247
let generatePDFObjectMarkup = function (embedType, targetNode, url, pdfOpenFragment, width, height, id, title, omitInlineStyles, customAttribute, PDFJS_URL){
230248

0 commit comments

Comments
 (0)