Reputation: 69
Is it allowed to have more than one window.addEventlistener("load", function, false);
?
Like this:
window.addEventlistener("load", function1, false);
window.addEventlistener("load", function2, false);
I know you don't have to, but is it wrong? Or is it allowed?
Upvotes: 3
Views: 1228
Reputation: 3101
window.addEventListener('load', function(){})
is allowed for multiple times
window.onload
will overwrite all load listeners.
window.addEventListener('load', function(){window.addEventListener('load', function(){})})
you should not use load event listener as IIFE, since than any more load listener you added nested-ly, will not execute.
Upvotes: 0
Reputation: 83215
It is allowed that is the difference between addEventListener
and window.onload =
.
The first can have multiple listeners. The latter, only one.
Upvotes: 2
Reputation: 71908
Yes, you can. In fact, that's one of the biggest advantages of addEventListener
versus a plain window.onload = function...
.
Upvotes: 2