Welcome to Geeklog Friday, November 24 2017 @ 07:26 pm EST


Status: offline

remy

Forum User
Full Member
Registered: 09/06/2003
Posts: 141
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.

PHP 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>
 


All times are EST. The time is now 07:26 pm.

  • 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