Correct Way of Adding JavaScript OnLoad Event to Drupal
In Drupal 4.7 and 5.x correct way to add your custom Javascript onload
events is to
a) Make sure there is no onload attribute on HTML body tag.
b) Make sure you are not calling window.onload= directly
c) Insert the following snippet, in the generic section (outside any
methods!) of your module’s javascript file:
if (isJsEnabled()) {
addLoadEvent(yourCustomJSFunction);
}
You can call addLoadEvent method as many times as you wish. It will stack-up multiple functions and call them in queue.