Managing multiple onLoad events with Prototype

Jun 16

This is an update to a previous article written way back in 2003 "Managing multiple onLoad events in JavaScript".

The article describes how to create an array of onload (window.onload) events in order to queue each event and enable the browser to perform onload sequentially. However this can all be forgotten in preference to the Prototype Javascript Framework and the useful Event Observe method.

Use Event.observe instead of using <body onload="return myFunction()"> or DOM Level-0 event property window.onload = myFunction;

Example
  1. Event.observe(window, 'load', function() { myFunction.init() });
  2. Event.observe(window, 'load', function() { myFunction2.init() });

Comments (2) Back home
Filed under:
Scripting
Posted by:
James Griffin
Dated:
June 16, 2007

2 comments

Warren Parsons at 7:25 PM on July 5, 2007

Sadly, this alone does not guarantee that the events will fire in the order you specify. I'm wrestling with this right now.

As these events are all set to fire when the window object is loaded, they all fire concurrently once the condition is satisfied, and it's left to the browser how to prioritize them.

Mr. Apache at 5:50 PM on August 10, 2007

Can the multiple onload function at AskApaches - favorite javascript '07 be used?