My website includes an embedded PDF file that sometimes takes a while to load, resulting in a blank screen for the user. I want to implement a preloader image, such as "LOADING...", while the PDF downloads in the background.
Here is the code snippet I am using:
document.getElementById("bigone").innerHTML =
'<object type="application/pdf" data="\\PDF\\somefile.pdf" width=100% height="720px"></object>';
I tried using the Image object in JS for the preloader but ran into issues:
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>';
}
Unfortunately, this approach didn't work as expected. The preloader image appears but isn't replaced with the embedded PDF. I even checked pdf.onload inside an alert and it returned null. Any suggestions or corrections to my code would be greatly appreciated. Thank you.