I want to detect when the <body> element finishes loading into the DOM from an external script without using an external JavaScript library. I do not want to use document.ready or window.onload because they do not fire until the entire DOM (including all external files) finishes loading.
I want to detect when the <body> element finishes loading into the DOM from
Share
Here’s a simple solution that works in ALL browsers:
Insert the following code above the
</body>tag in the HTML:Insert this code in the external javascript:
Place all the code in the external javscript that needs to be run on the page’s load into a function called
ONLOAD. For example:The first part covers instances when the external javascript finishes loading before the HTML, and the second part, vice-versa.