Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda