I have a website that displays a pdf file embedded in the browser. The code for it is below:
document.getElementById("bigone").innerHTML =
'<object type="application/pdf" data="\\PDF\\somefile.pdf" width=100% height="720px"></object>';
Basically using innerHTML to insert an object tag with a PDF as its data ("bigone" is a table cell). This works perfectly fine, but sometimes the PDF's are large at take time to load, and the user is faced with a blank screen. I want to insert an image preloader (like the text "LOADING...") while the pdf file downloads in the background.
I've using the Image object in JS but have had no success.
document.getElementById("bigone").innerHTML = '<img src="gradients\\loading.png" />'
var pdf = new Image();
pdf.src = "\\PDF\\somefile.pdf";
pdf.onLoad = function() {
document.getElementById("bigone").innerHTML = '<object type="application/pdf" data="\\PDF\\somefile.pdf" width=100% height="720px"></object>';
}
This doesn't work, the preloader image appears, but isn't replaced with the embedded PDF. I placed pdf.onLoad inside an alert and it returned null. Is there anything wrong with my code, or any ideas anyone has to offer? Thanks.