Last active
November 2, 2024 01:51
-
-
Save trafficinc/72fae98f94a3c8ac4e220b37a628b744 to your computer and use it in GitHub Desktop.
On-Load Functions, when page is fully loaded (JS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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