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

409
Views
Cómo obtener el ícono svg como una cadena de un archivo .svg

¿Hay alguna manera de obtener el ícono svg como una cadena mientras tiene el archivo .svg con JavaScript?

Para ser más claro, necesito una función que haga:

 function svgFileToString('./icon.svg'){ ... ... return `<svg>...</svg>` }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede utilizar la función fetch() . La función svgFileToString() no devolverá nada, pero puede reemplazar console.log(text); con lo que sea

Para el ejemplo, estoy usando una URL de datos para reemplazar la ruta real a un archivo.

 function svgFileToString(iconpath){ fetch(iconpath) .then(response => response.text()) .then(text => { console.log(text); // do whatever }); } //svgFileToString('/icon.svg'); // for testing here on ST: svgFileToString('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MCIgaGVpZ2h0PSI1MCI+CiAgPHJlY3Qgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgZmlsbD0iZ3JlZW4iIC8+Cjwvc3ZnPgo=');

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!