Skip to content

Instantly share code, notes, and snippets.

@tex2e
Last active September 28, 2017 03:15
Show Gist options
  • Save tex2e/733ebd69cba9e1e442c9bd363f44a47d to your computer and use it in GitHub Desktop.
Save tex2e/733ebd69cba9e1e442c9bd363f44a47d to your computer and use it in GitHub Desktop.
Resolve promise when document onload
// Resolve promise when document onload
function awaitDOMContentLoaded() {
return new Promise(function (resolve) {
if (document.readyState === "complete") {
resolve();
} else {
document.addEventListener("DOMContentLoaded", resolve);
}
});
}
awaitDOMContentLoaded()
.then(process1)
.then(process2)
.then(...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment