Im trying to embed a PDF on to my page, but the PDF just does not load. I have checked the file path which is correct.
When the page first loads, I get a blank grey embed field, however when I click on the embed, I get this (which stays like this):

<script>
var selected_doc_ref = "";
function getPDF() {
//selected_doc_ref = "395";
var DV_pdf_path = "../../../Document_Viewer/Risk_Assessment/RISK ASSESSMENT 1024.pdf";
var pdf = document.getElementById("pdf");
var clone = pdf.cloneNode(true);
clone.setAttribute('src', DV_pdf_path);
pdf.parentNode.replaceChild(clone, pdf)
}
</script>
<body onload="getPDF()">
<embed id="pdf" style="border-radius: 10px;position: relative;top:0;right:0;left:0;bottom:0;width:100%;height:620px;"/>
Any ideas where I am going wrong?
Thanks
As the browser does not refresh the embed tag when you add the src attribute to the <embed> tag after page load you have 2 options:
<embed> tag directly so it is available from the beginning on. You could set the src through code behind or as a static value.In your javascript, add the whole <embed> tag inside the getPDF() function instead of just the attribute src:
var e = document.createElement('embed');
e.attributes['src'] = src;
e.attributes['style'] = "border-radius: 10px;position: relative;top:0;right:0;left:0;bottom:0;width:100%;height:620px;";
document.getElementById("pdfContainer").appendChild(e);
Assuming that you have a element with id "pdfContainer" where you want to place the <embed> tag inside.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With