Document ready v čistom JavaScripte

if (document.readyState === 'complete') {
  // The page is fully loaded
}

when the document is ready…

let stateCheck = setInterval(() => {
  if (document.readyState === 'complete') {
    clearInterval(stateCheck);
    // document ready
  }
}, 100);

or with onreadystatechange

document.onreadystatechange = () => {
  if (document.readyState === 'complete') {
    // document ready
  }
};

Use document.readyState === 'interactive' to detect when the DOM is ready.

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená.