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

120
Visualizações
JavaScript within <script> tags are not being executed in an iframe

I am building a simple online HTML IDE where students can type HTML into a codemirror editor and then when a button is clicked, the HTML is placed in an iframe to render the page.

My code in question:

function runit() { 
   var prog = myCodeMirror.getValue(); 
   var mypre = document.getElementById("output");
   mypre.contentDocument.body.outerHTML = prog; 
 
}

prog is the html from the editor, mypre is the iframe.

All html placed within <body> tags is correctly executed in the iframe. All css code placed within <style> tags is correctly executed in the iframe. However, any javascript placed within <script> tags is not executed in the iframe.

How can I get <script> tag contents to be correctly executed in the iframe?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This may help:

const runit = () => document.getElementById("output").srcdoc = myCodeMirror.getValue();

We use the property srcdoc to change the content in the iframe as HTML

about 4 years ago · Juan Pablo Isaza Relatório
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