Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Cómo leer y mostrar archivos html

Estoy haciendo un editor html, pero el problema es que cuando alguien necesita ver un archivo html, no sé cómo mostrar el texto del archivo.

 <input type="file" onchange="previewFile()"><br> <p id="txt1" src="blank.html"></p>
 <script> function previewFile() { const preview = document.getElementById('txt1'); const file = document.querySelector('input[type=file]').files[0]; const reader = new FileReader(); reader.addEventListener("load", function () { // reads image file to a blob string preview.src = window.URL.createObjectURL(file); }, false); if (file) { reader.readAsDataURL(file); } } </script>

Usé este script para leer un archivo y mostrarlo cambiando el párrafo src a un enlace de blob, pero parece que el párrafo no obtiene el texto mediante un enlace de texto html usando src. ¿Hay una manera de hacerlo?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

El párrafo no tiene el atributo src . Debe usar innerText o innerHTML para mostrar el contenido.

 function previewFile() { const content = document.querySelector('.content'); const [file] = document.querySelector('input[type=file]').files; const reader = new FileReader(); reader.addEventListener("load", () => { // this will then display a text file content.innerText = reader.result; }, false); if (file) { reader.readAsText(file); } }
 <input type="file" onchange="previewFile()"><br> <p class="content"></p>

about 4 years ago · Juan Pablo Isaza Report

0

La etiqueta p no admite el atributo src , por lo que las soluciones alternativas serían usar element.innerHTML= text o cambiar la etiqueta p a iframe

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!