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

275
Vistas
window.postmessage() data is not recieved instantly rather than i have put a setTimeout function to pass the data

I am using window.postmessage() to send the data across domains to a popup but, postmessage is not sending the data instantly i.e. when captured on other domain in constructor of a component the data is not coming. If given a setTimeout i.e. delay of around 1 sec then data is coming. What could be the issue?

Here's the code:

Parent:

var popup = window.open(
                "http://localhost:4300",
                'winname',
          );
    popup.postMessage('response', '*');

Popup-Window:

window.addEventListener('message', (event) => {
console.log(event.data)}

I should be getting data as response but I am getting data as undefined in console.

Also, If i put the code below in Parent:

setTimeout(() => {
              popup.postMessage('response', "http://localhost:4300");
            }, 2000);

I am able to get the data as "response" in console in popup.

I want to get rid of setTimeout and get the data as soon as poosible. Please help.

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