Welcome to Geeklog, Anonymous Saturday, November 23 2024 @ 03:26 am EST

Geeklog Forums

multiple onLoad triggers: howto


Status: offline

remy

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)
                        function1();
                if (function2)
                        function2();
        }
}
</script>

// 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);
</script>
 

 Quote

All times are EST. The time is now 03:26 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