This has not been answered here or there. These questions are poorly worded, and the answers are all along the lines of "use DOMReady".
I want to ensure that code is run only if the page has finished loading. I cannot alter the HTML file itself, but if I could, I would do something that amounts to this:
<!DOCTYPE html>
<html>
<head>
<script>window.loaded=false;</script>
</head>
<body onload="window.loaded=true;">
<!-- ... -->
</body>
</html>
Then in my code:
if (window.loaded) { run(); }
else { document.addEventListener("load", run); }
And that would achieve exactly what I want. Unfortunately, I cannot modify the HTML, which means that I am looking for a way to determine whether the document has loaded (not if the DOM is ready) from JS code only.
I have looked around quite a bit, but so far, all I have found revolves around DOMReady. Has no-one really ever looked for this?