What is the difference between addEventListener and attachEvent? [duplicate]

Quick answer: you have to use attachEvent if your browser returns undefined == window.addEventListener. Thing is the former is a non-standard JS function implemented in IE8 and previous versions, while addEventListener is supported by IE9+ (and all the other browsers).

So the big question is: are you gonna support IE8-?

Margin note: window.onload = whatever will override any attached event listeners. This is why addEventListener is used: to add a function to the event’s stack, instead of overwriting it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)