window.onload VS window.addEventListener

L00PeR
7 years ago

0

Hi again xD.

I would like to know which are the differences between:
window.onload=function;
and
window.addEventListener("load",function,false);

2replies
2voices
1,849views
kakarot007
7 years ago

0

I think the addEventListener allows you to add your own custom events .

onload is inbuilt event whereas you have created an custom event named load .

I might be wrong !!

L00PeR
7 years ago

0

yeah you are rigth but i mean using addEventListener(“load”,function,false);

let me explain beter:

window.onload=function;
AND
window.addEventListener("load",function,false);
Both do exactly the same, but some people say that is beter to use the second one.
My question is: Why is better to use the second one?

You must be logged in to reply to this discussion. Login
1 of 3

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss