I need to use the unload and load events in the body tag.

Is there a suitable hook to enable me to do this?

eg., I want this ...

Comments

ceejayoz’s picture

Things are handled a little differently in Drupal, as many modules may need to do things onload. Instead of piling them all in an onload attribute, we use jQuery's $(document).ready() function:

<script type="text/javascript">
if (Drupal.jsEnabled) {
  $(document).ready(function() {
    // onload functionality here!
  }
}
</script>

This has the added benefit of running before onload would, as onload waits for images etc. to load - if you have a lot, it could take forever to run. It can be added to the page by a module using something like drupal_add_js() or drupal_set_html_head().