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

157
Vistas
JS: iFrame contentWindow returns null

I want to call a function when a button within an iframe is clicked, but I am already having problems accessing the iframe document.

First, I followed this video, but null is returned when the function is called. The iFrame's content is hosted on the same server, using a wordpress installation in a folder (mydomain.com/fragen). The main page is mydomain.com, so that should not be the issue, right? Here is the code I was using. Printing a string to the console works.

<button onclick="test()">Test</button>

<iframe id="myIframe" src="mydomain.com/fragen/wp-admin/admin-ajax.php?action=h5p_embed&id=24" width="100%" height="525" frameborder="0" allowfullscreen="allowfullscreen" title="Diagnosetext">
</iframe>

<script>
const myIframe = document.querySelector("#myIframe");

function test() {
    const iframeWindow = myIframe.contentWindow;
    console.log(iframeWindow);
}
</script>
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