onload

[Total: 0    Average: 0/5]

This shows how to create multiple functions that run in response to the onload event. Each function need not know or care about the other routines that are going to run at “onload()”. that is unless you need a priority system…

Head Code:

<!-- Replace the <body> tag with this tag to get this example to work for you.
<body onload="init()">
-->

Body Code:

<script type=text/javascript>
onLoad="init()";
var _initFunctions = new Array();
function addInit(_f) {
  _initFunctions[_initFunctions.length] = _f;
  if (_f.indexOf("()") == -1)
    _initFunctions[_initFunctions.length-1] += "()";
}
function init() {
  for (i in _initFunctions) {
    eval(_initFunctions[i]);
  }
}

function alert1() { alert("alert1"); }
function alert2() { alert("alert2"); }
function alert3() { alert("alert3"); }

addInit("alert1()");
addInit("alert2()");
addInit("alert3");

</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *