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.