Welcome to Geeklog, Anonymous Friday, July 12 2024 @ 11:23 am EDT

Geeklog Forums

multiple onLoad triggers: howto

Status: offline


Forum User
Full Member
Registered: 06/09/03
Posts: 162
Location:Rotterdam & Bonn
Some javascripts, some blocks and some staticpages need to controle the window.onLoad event and do some stuff, like populating a drop down. They trigger the event window.onload or replace the function window.onload. A classic race condition.

This can be circumvented by defining a doubleDelegat function. This ensures that the various onLoad functions are executed one after each other.

Text Formatted Code

// this should be in <head>…..</head>

<script language="JavaScript" type="text/javascript">
function makeDoubleDelegate(function1, function2) {
        return function() {
                if (function1)
                if (function2)

// this is put in place where you need it

<script language="JavaScript" type="text/javascript">
myWindowInit=function() {
   // do your stuff
window.onload = makeDoubleDelegate(window.onload, myWindowInit);


All times are EDT. The time is now 11:23 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content