[Web4lib] Valid substitute for body onLoad()

Tom Keays tomkeays at gmail.com
Mon Oct 30 18:49:26 EST 2006


Simon Willison came up with the standard way to do this via a DOM
event handler. See if it solves the problem.

http://simon.incutio.com/archive/2004/05/26/addLoadEvent

The actual code involved:

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
addLoadEvent(function() {
  /* more code to run on page load */
});


On 10/30/06, Robert Sullivan <robert.g.sullivan at gmail.com> wrote:
> I have found an almost-pure CSS method method for drop down menus
> which works across browsers and validates, except that it uses a small
> piece of Javascript which is called by <body onLoad>.
>
> That won't pass the validator and since I don't speak Javascript I am
> looking for an alternative means of doing that.  The site I saw this
> on:
>
> <http://www.projectseven.com/tutorials/navigation/auto_hide/index.htm>
>
> says you may replace that with a window.onload in the script file, but
> before I get in any deeper I am asking people who actually know what
> they're doing. :-)
>
> --
> Bob Sullivan
> Schenectady Digital History Archive
> <http://www.schenectadyhistory.org/>
> Schenectady County (NY) Public Library
> _______________________________________________
> Web4lib mailing list
> Web4lib at webjunction.org
> http://lists.webjunction.org/web4lib/
>


-- 
Tom


More information about the Web4lib mailing list