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

69
Vistas
React With Other Javascript to Handle Iframe Events

I am rendering an iFrame developed by a different org using:

<script type="text/javascript" src="https://externalUrl/popup.js"></script>
<iframe ref={iframeRef} id="ImportantFrame" src={iframeURL}></iframe>

The iframe contains among other things a close button, which when clicked calls a non-existent 'closePopUp()` function:

closePopUp function call screenshot

How can I insert my own function into my website which will handle this call if I cannot directly modify the code rendered by the iFrame?

Attempt 1

I tried embedding a function directly into my react code:

function closePopup() {
    console.log('called react script')
}

But that didn't get called.

Attempt 2

I also tried creating a vanilla JS file with the following:

function closePopup() {
    console.log('called custom script')
}

document.addEventListener("DOMContentLoaded", function(){
    console.log('document loaded')
});

'document loaded' did appear on page load confirming that my custom vanilla JS works, but closePopUp() didn't get called.

Is there a way I can handle the function call without directly modifying the source code inside the rendered iFrame?

about 4 years ago · Santiago Trujillo
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