Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda