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

108
Vistas
Add custom HTML in iFrame that already has a page loaded in it

I have a button and an iframe. When button is clicked, it opens a page in the iframe. I have another button, when it is clicked, it is supposed to add custom html to the already loaded page in the iframe, but it is not working.

HTML:

<a href="#" onclick="site_load_1();" id="site_button_1">Load page in Iframe</a>
<a href="#" onclick="update_iframe();">Update iframe</a>
<iframe src="" width="100%" height="500px" id="main_iframe"></iframe>

The jQuery to load page in iframe is working fine:

function site_load_1() {
    $('#main_iframe').attr('src', "https://bing.com");
}

The jQuery to update iframe with custom html is not working:

function update_iframe() {
    var myFrame = $("#main_iframe").contents().find('body');
    var newContent = "<h1>hello</h1>";
    myFrame.html(newContent);
}

However, it does work when the iframe is empty, as in, when page has not been loaded into it via the first button.

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