You cannot install multiple event handlers; they are not supported. If you need to perform several functions, you just need to call them sequentially one after another:
function f1() { ... } function f2() { ... } function f3() { ... } window.onload = function() { f1(); f2(); f3(); }
Most javascript libraries provide you with ways to add a few function calls to the event handler - and will chain you. For example, using jQuery you can do this:
$(window).load(function() { ... }); $(window).load(function() { ... }); $(window).load(function() { ... });
This will not cancel the previous call with the new one, but will trigger all three calls from the onload
.
UPDATE: another way to deal with it is to use addEventListener
for your window
object.
function f1() { ... } function f2() { ... } function f3() { ... } window.addEventListener("load", f1); window.addEventListener("load", f2); window.addEventListener("load", f3);
or even
window.addEventListener("load", function() { ... }); window.addEventListener("load", function() { ... }); window.addEventListener("load", function() { ... });
These two pieces of code are equivalent to the first - and to each other.
source share