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

217
Visualizações
How to display an image from an input file inside an iframe?

I'm trying to build a rich text editor without any frameworks, and I want to input images to the text box, which is an iframe. How do I display the image inside the text box just by opening it?

That's what I have so far:

//Show Image in Text Box
function showImg() {
  const textBox = document.getElementbyID("textBox");
  const imgFile = document.querySelector("input[type=file]").files[0];

  textBox.onload = function(e) {
    const image = document.createElement("img");
    image.src = e.target.result;
    document.body.appendChild(image);
  }
  textBox.readAsDataURL(imgFile);
}
iframe {
  border: 0;
  width: 100%;
  margin-bottom: 5pt;
  height: 250pt;
}

.fas {
  color: #f85991;
  font-size: 50pt;
}

.hidden {
  display: none;
}
<!-- Input File -->
<div class="hidden">
  <input type="file" name="imageUpload" accept="image/*" id="imageUpload">
</div>

<!-- Image Button -->
<label for="imageUpload" title="Inserir Imagem">
        <i class="fas fa-image"></i>
</label>

<!-- Text Box -->
<iframe name="richTextField" id="textBox" contenteditable="true"></iframe>


<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.0.0/css/all.css">

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