How do I insert HTML just before the body closing tag?
The equivalent of hook_footer() that was used in Drupal 6 is to implement hook_page_build(), and alter the content of $page['page_bottom'], using code similar to the following one:

function mymodule_page_build(&amp;$page) {
  $page['page_bottom']['devel'] = array(
    '#weight' =&gt; 25, 
    '#markup' =&gt; '&lt;div style="clear:both;"&gt;' . devel_query_table() . '&lt;/div&gt;',
  );
}


The content of $page['page_bottom'] is output from html.tpl.php, using the following code:

  &lt;?php print $page_top; ?&gt;
  &lt;?php print $page; ?&gt;
  &lt;?php print $page_bottom; ?&gt;
&lt;/body&gt;
&lt;/html&gt;


The value of $page_bottom is initialized from template_process_html() using the following code:

  // Render page_top and page_bottom into top level variables.
  $variables['page_top'] = drupal_render($variables['page']['page_top']);
  $variables['page_bottom'] = drupal_render($variables['page']['page_bottom']);
  // Place the rendered HTML for the page body into a top level variable.
  $variables['page'] = $variables['page']['#children'];
  $variables['page_bottom'] .= drupal_get_js('footer');


The difference between hook_page_alter() and hook_page_build() is that hook_page_alter() is executed after hook_page_build() and should be used to alter, or remove content added by another module, while hook_page_build() should be used to add new content to the page.