You can use the document.readyState
property to check if a document is loaded without listening to any events. It will be set to "complete"
to check if the document and all sub resources are loaded. (This corresponds to the load
event.)
function checkLoaded() { return document.readyState === "complete"; }
If you only want to check if the document is loaded without worrying about sub-resources, you can also check if there is an "interactive"
property.
function checkLoaded() { return document.readyState === "complete" || document.readyState === "interactive"; }
This should work in current browsers, but is not supported in older versions of all browsers.
source share