javascript run onload code example
Example 1: 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 2: load js
// Log a message when the page is fully loaded:
window.addEventListener('load', (event) => {
console.log('page is fully loaded');
});