Answers for "javascript after page load event"

17

JavaScript that executes after page load

//two ways of executing JS code after page is loaded, use "DOMContentLoaded" when able

document.addEventListener("DOMContentLoaded", function(){
    //dom is fully loaded, but maybe waiting on images & css files
});

window.addEventListener("load", function(){
    //everything is fully loaded, don't use me if you can use DOMContentLoaded
});
Posted by: Guest on July-31-2019
1

html tag run only after whole page is loaded

//put your JS code in
document.onload = function {
	// the code here will run when all the HTML is loaded (but the css and the images may miss)
}

// or in
window.onload = function {
  // the code here will run when the whole page is loaded (including css and images)
}
Posted by: Guest on September-11-2020
1

html tag run only after whole page is loaded

<body onload="script();">
<!-- will call the function script when the body is load -->
Posted by: Guest on September-11-2020

Code answers related to "javascript after page load event"

Code answers related to "Javascript"

Browse Popular Code Answers by Language