Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API

From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
ElectroArchiver3115134dIt's not the same,
addEventListener adds one listener,
while onmessage replaces all with
you function -
CoreFusionX1460134dStill, I don't know if that was his specific issue, but, in my limited frontend knowledge, shouldn't his callback be invoked no matter how he registered it?
-
Cyanide13938133d@ElectroArchiver So if there are 5 different components using “window.onmessage”, there will actually be only one registered listener?
-
ElectroArchiver3115133d@Cyanide Exactly, you can try this in a new tab with devtools console opened:
window.onclick = () => console.log('test1')
window.onclick = () => console.log('test2')
You will only see 'test2' in the log when you click -
CoreFusionX1460133d@ElectroArchiver
Yes, but he specifically mentions that he fixed it by switching to .onmessage, which suggests he only has one listener whatsoever, which, again, *should*have been called with .addEventListener too. -
ElectroArchiver3115133d@CoreFusionX Sure, I was answering his questions on how JS works, nothing more.
-
CoreFusionX1460133d@ElectroArchiver
Yeah, all good. Yet I still want to know how it even happened in the first place. 😂 -
ElectroArchiver3115133d@CoreFusionX Well, he might have stopped event propagation in another listener..
Related Rants
I had been banging my head on an issue for 2 days. The solution?
Replaced
“window.addEventListener(“message”, callback)”
with
“window.onmessage = callback”
What. The. Actual. Fuck??!!
Aren’t they supposed to be the same thing?? It’s written on MDN’s article that the latter is an alternative way of doing the former.
What the fuck then? I am actually really pissed right now. Ragefully pissed.
rant
event
mdn
listener
web