Sometimes, we want to detect if document has loaded with JavaScript.
In this article, we’ll look at how to detect if document has loaded with JavaScript.
How to detect if document has loaded with JavaScript?
To detect if document has loaded with JavaScript, we can check if document.readystate
is set to 'complete'
.
For instance, we write
if (document.readyState === "complete") {
init();
}
to check if document.readystate
is 'complete'
.
If it is, then document
has loaded.
Conclusion
To detect if document has loaded with JavaScript, we can check if document.readystate
is set to 'complete'
.