Skip to content

Commit

Permalink
Adjustments for IE11
Browse files Browse the repository at this point in the history
Can't wait to drop IE11. :/
  • Loading branch information
pipwerks committed Feb 14, 2024
1 parent f4b7e99 commit ab99e5d
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
8 changes: 5 additions & 3 deletions dev/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ <h2>Tests</h2>
document.getElementById("quicklaunch").addEventListener("click", function(e){
e.preventDefault();
let links = document.querySelectorAll("#examples li a");
links.forEach(function(link){
window.open(link.href, "_blank");
});
//Can't use forEach because IE11 doesn't support it
for(let i=0; i<links.length; i++){
window.open(links[i].href, "_blank");
};
});

</script>

</body>
Expand Down
36 changes: 27 additions & 9 deletions dev/pdfobject.2.3b.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,33 @@

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

fetch(b64).then(response => response.blob()).then(blob => {
let link = document.createElement('a');
link.innerText = "Download PDF";
link.href = URL.createObjectURL(blob);
link.download = filename;
targetNode.innerHTML = fallbackHTML.replace(/\[pdflink\]/g, link.outerHTML);
});

}
//IE-11 safe version. More verbose than modern fetch()
if (window.Blob && window.URL && window.URL.createObjectURL) {

var xhr = new XMLHttpRequest();
xhr.open('GET', b64, true);
xhr.responseType = 'blob';
xhr.onload = function() {

if (xhr.status === 200) {

var blob = xhr.response;
var link = document.createElement('a');
link.innerText = "Download PDF";
link.href = URL.createObjectURL(blob);
link.setAttribute('download', filename);
targetNode.innerHTML = fallbackHTML.replace(/\[pdflink\]/g, link.outerHTML);

}

};

xhr.send();

}

};


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

Expand Down
8 changes: 5 additions & 3 deletions dev/tests/pdf-open-params.html
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,11 @@ <h1>PDFObject Example: PDF Open Parameters</h1>

};

document.querySelectorAll("li a").forEach(function(el){
el.addEventListener("click", clickHandler);
})
//Can't use forEach because IE11 doesn't support it
let links = document.querySelectorAll("li a");
for(let i=0; i<links.length; i++){
links[i].addEventListener("click", clickHandler);
}
</script>

</body>
Expand Down
2 changes: 1 addition & 1 deletion dev/tests/pdfjs.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h1>PDFObject Example: PDF.js fallback</h1>

<script src="/dev/pdfobject.2.3b.js"></script>
<script>
let myPDF = PDFObject.embed("https://pdfobject.com/pdf/sample-3pp.pdf", "#pdf", {
let myPDF = PDFObject.embed("/pdf/sample-3pp.pdf", "#pdf", {
pdfOpenParams: {
navpanes: 0,
toolbar: 0,
Expand Down

0 comments on commit ab99e5d

Please sign in to comment.