Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
Message event not following the order of event listeners execution with capture parameter in addEventListener

I was going through this article about Javascript Eventing where the author beautifully explained about three phases of eventing(capturing, target, bubbling) and how events originate and how they travel in the DOM. According to it, the event first travels in the capture phase, then target phase and in end, it goes through bubbling phase.Hence,if there are two listeners attached on the same element for the same event, one at capturing phase and another at bubbling phase, then the event listener attached at capturing phase will be called first followed by event listener attached at bubbling phase.

I tried the above process for click event and message event. The click event is following the above behaviour but message event is not. Please find the code snippets for both cases:

window.addEventListener("message", function(e) {console.log("FALSE MESSAGE");}, false); 
window.addEventListener("message", function(e) {console.log("TRUE MESSAGE");}, true);

window.addEventListener("click", function(e) {console.log("FALSE CLICK MESSAGE");}, false);
window.addEventListener("click", function(e) {console.log("TRUE CLICK MESSAGE");}, true);

Message Event Case

Click Event Case

Why message event is behaving differently and not like other normal events?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda