onload Function Chaining

onload Function Chaining using addEventListener

If it does not matter when during the onload event the JavaScript code is executed, simply add an event listener using addEventListener, passing the event object as a parameter:

function init(ev) {
   if (! ev) ev = window.event;
   ... any JavaScript code here runs when the onload event has been triggered ...
}
window.addEventListener("load", init);