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

140
Views
leer y mostrar un texto de un archivo línea por línea usando javascript en la página html

Estoy aprendiendo javascript, así que necesito su ayuda. Tengo un archivo de texto, como el siguiente;

 Text1 Text2 Text3 ..... ..... Textn

Me gustaría leer todo el contenido del archivo línea por línea, texto por texto y mostrarlo en la página html uno por uno. Un texto parpadeará, desaparecerá y luego el siguiente texto parpadeará, desaparecerá, etc. Cuando llegue al final, comenzará desde el principio del archivo y continuará línea por línea.

¿Cómo puedo hacerlo?

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

0

Puedes hacerlo de esta manera:

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example</title> </head> <body> <h1 id="my-element">Value</h1> <script> var target = document.getElementById("my-element"); var content = null; var xhr = new XMLHttpRequest(); xhr.open("GET", "content.txt"); xhr.onload = () => { content = xhr.response.split(/\r?\n/); let counter = 0; setInterval(() => { target.innerHTML = content[counter++ % content.length]; setTimeout(() => target.innerHTML = "", 500); }, 1000); }; xhr.send(); </script> </body> </html>

Pero tenga en cuenta que no funciona con el protocolo file y debe ejecutar un servidor local para usarlo.

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!