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

162
Vistas
Post message to cross-origin iframe in JavaScript

I'm new to JavaScript, and I'm trying to post a message to my iframe in order to scroll it. I'm trying to achieve it using this code.

scroll(i) {
  var src = $("#iframe").attr("src");
  $("#iframe").contentWindow.postMessage(i, src);
}

This code is working when launched in Chrome console, but it is not working when launched from the Webapp (using a button).

I get an error saying contentWindow is undefined. Does someone know why?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

$(document).ready(function(){
  $(window).scroll(function() {
   scroll("yourHtmlFile.html");
  });    
 function scroll(i){
    $("#iframe").attr("src",i);
 }});
about 4 years ago · Juan Pablo Isaza Denunciar

0

For some reason it seems my code was managing $("#iframe") as an array. I got this issue solved by doing this:

scroll(i) {
  var src = $("#iframe")[0].attr("src");
  $("#iframe")[0].contentWindow.postMessage(i, src);
}
about 4 years ago · Juan Pablo Isaza Denunciar
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