1if( document.readyState !== 'loading' ) {
2 console.log( 'document is already ready, just execute code here' );
3 myInitCode();
4} else {
5 document.addEventListener('DOMContentLoaded', function () {
6 console.log( 'document was not ready, place code here' );
7 myInitCode();
8 });
9}
10
11function myInitCode() {}
1let stateCheck = setInterval(() => {
2 if (document.readyState === 'complete') {
3 clearInterval(stateCheck);
4 // document ready
5 }
6}, 100);
1if (document.readyState === 'complete') {
2 // The page is fully loaded
3}