Skip to content

Instantly share code, notes, and snippets.

@trafficinc
Last active November 2, 2024 01:51
Show Gist options
  • Save trafficinc/72fae98f94a3c8ac4e220b37a628b744 to your computer and use it in GitHub Desktop.
Save trafficinc/72fae98f94a3c8ac4e220b37a628b744 to your computer and use it in GitHub Desktop.
On-Load Functions, when page is fully loaded (JS)
<script>
(function () {
function ready(fn) {
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
function init() {
console.log("We are ready now!");
}
ready(init);
})();
// ----------------- OR
window.onload = function() {
console.log('Page is fully loaded');
};
// ----------------- OR
window.addEventListener('load', (event) => {
console.log('Page is fully loaded');
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment