Chris
0
Q:

javascript execute code on 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
window.addEventListener('load', (event) => {
  console.log('page is fully loaded');
});
0
<html>
 
  <body onload="loaded();"></body>
  <script>
    function loaded() {
      alert('Page is loaded');
    }
 
  </script>
 
</html>
0

object.addEventListener("load", myScript);
 
1

New to Communities?

Join the community