0
Q:

Javascript run code 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
});
7
<html>
 
  <body onload="loaded();"></body>
  <script>
    function loaded() {
      alert('Page is loaded');
    }
 
  </script>
 
</html>
0
<body onload="script();">
<!-- will call the function script when the body is load -->
1

New to Communities?

Join the community