onload is a window property. It acts like any other property of a variable. When you try to use it twice, you overwrite the original value with your second record.
Thus, your entire external script is ignored when it is ported to window.onload , because window.onload then overwritten as
function() { console.log("hello from html"); };
If you want to perform 2 functions, define 2 functions, a and b ,
and set window.onload as follows:
window.onload = function(){ a(); b(); }
Alternatively, you can link 2 separate events as Alcides suggests. My personal opinion is that its cleaner makes one binding to several functions, since it is easier to find out what is connected, to know in what order your functions will be executed, and to see everything that happens in one place, but basically this is a question style / preference if order doesn't matter.
source share