xxxxxxxxxx
//Use window.onload to to execute JavaScript only after the HTML has loaded
//Syntax:
window.onload = function() {
//JavaScript goes here
}
xxxxxxxxxx
//How to load function after the page has loaded?
window.addEventListener('load', function() {
console.log('All assets are loaded')
})
xxxxxxxxxx
//How to load the function after the window has loaded?
$(window).on('load', function() {
console.log('All assets are loaded')
})
xxxxxxxxxx
When do they fire?
window.onload
By default, it is fired when the entire page loads, including its content (images, CSS, scripts, etc.).
In some browsers it now takes over the role of document.onload and fires when the DOM is ready as well.
document.onload
It is called when the DOM is ready which can be prior to images and other external content is loaded.