hook_onload() replacement I want to add JS functions to the body tag's onload and onunload attributes with a custom module. The only hook I found was hook_onload() from Drupal 4.7, but this method has been deprecated. What is the Drupal 7 way of achieving this?
You don't use PHP hooks to execute Javascript. You would put the Javascript you want to execute into a .js file, and then use PHP to just attach that file to any page where it is needed, for example, using drupal_add_js().

For example if you wanted to attach it to every page with a certain type of form you would put drupal_add_js() inside of a hook_form_FORM_ID_alter). 

If you want it on every page all the time, you can add it to your module's .info file like so:

scripts[] 'path/to/js/foo.js