let bDomLoaded = false; if (document.readyState != "loading") { bDomLoaded = true; } if (!bDomLoaded) { document.addEventListener ("DOMContentLoaded", function() { MyFunction(); } ); } else { MyFunction(); }