I’m not a developer and I was not built to write code! I’m using GitHub pages to host a very simple site with a very chunky pdf.
I want the site to land on a loading screen which disappears when the pdf is visible, but the loading screen always disappears almost instantaneously, leaving a blank grey screen on the PDF for about seven seconds before it finally loads.
Here’s the code:
<div id="preloader">
<div class="loader">
<Img src="loadingscreentest.png"></Img>
</div>
</div>
<div class="content">
<iframe src="InProgTest5.pdf#toolbar=0&navpanes=0&scrollbar=0&frameBorder=0&view=FitH" type='application/pdf' onload="killloadscreen()"></iframe>
</div>
<script>
function killloadscreen(){
const preloader = document.getElementById('preloader');
const content = document.getElementById('content');
preloader.style.display = 'none';
content.style.display = 'block';
}
</script>
I also tried event listeners with window.onload and DOMContentLoaded to hide the loading screen and show the content, but these bore the same results (or worse, with no loading screen showing up at all). I searched around the internet for clues and fixes and tried a few different things to no avail. One insight I found which I fear could be the answer is that there could be interference from the service being used to host the code (Pages, in my case). I’ve been informed that Pages is intended for static websites, so maybe it was always liable to disagree with moving parts like events and scripts? I know very little about this stuff.
Anyway, is there a solvable reason the onload event is triggered before everything is fully loaded? Or is there a way to determine for certain when the contents of the pdf become visible? Or is the code itself wrong? Or perhaps I need a workaround like something that can detect the color of a given pixel behind the loading screen (that seems flimsy to me, but I’m grasping at straws)? If hosting is likely the issue, I’ll absolutely look for a different platform.
Thanks for reading! Any help is appreciated. I am relying on this PDF, and I’m afraid having it blank without a loading screen (or something) is not an option!
