Append to Body onLoad

I looked for a long time how I could add JavaScript functions to an HTML document’s onLoad attribute.

Eventually I found this, something so obvious that I had considered trying it but foolishly didn’t try.

var oldLoad = window.onload;
window.onload = function() {
  oldLoad();
  function2();
}