1//two ways of executing JS code after page is loaded, use "DOMContentLoaded" when able
2
3document.addEventListener("DOMContentLoaded", function(){
4 //dom is fully loaded, but maybe waiting on images & css files
5});
6
7window.addEventListener("load", function(){
8 //everything is fully loaded, don't use me if you can use DOMContentLoaded
9});
1//put your JS code in
2document.onload = function {
3 // the code here will run when all the HTML is loaded (but the css and the images may miss)
4}
5
6// or in
7window.onload = function {
8 // the code here will run when the whole page is loaded (including css and images)
9}
1<body onload="script();">
2<!-- will call the function script when the body is load -->