javascript on script load code example

Example 1: on load javascript

window.onload = (event) => {
  console.log('page is fully loaded');
};

Example 2: javascript on script loaded

function loadScript( url, callback ) {
  var script = document.createElement( "script" )
  	  script.type = "text/javascript";
 	  script.onload = function() {
     	callback()
      };
}
// call the function...
loadScript("js/myscript.js", function() {
  alert('script ready!'); 
});

Example 3: run on load js

function codeAddress() {
            alert('ok');
        }
window.onload = codeAddress;

Tags:

Html Example