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

128
Views
Por qué el color hexadecimal no funciona con URL de datos utf8 para SVG

Me pregunto por qué no puedo usar colores HEX con estilo cuando llamo a un svg desde la URL de datos utf8 .

Cuando lo llamo con color rgb, funciona perfectamente bien:

 <img src='data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="100" width="100"><defs><style>.roundShape{fill:rgb(38, 167, 253);}</style></defs><circle cx="50" cy="50" r="40" class="roundShape" /></svg>'>

Pero, si uso el color HEX, el svg no se muestra:

 <img src='data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" height="100" width="100"><defs><style>.roundShape{fill:#26a7fd;}</style></defs><circle cx="50" cy="50" r="40" class="roundShape" /></svg>'>

Curiosamente, en base64 todo funciona bien:

 <img id='imgBase64'> <script type="text/javascript"> document.getElementById('imgBase64').src = 'data:image/svg+xml;base64,'+btoa('<svg xmlns="http://www.w3.org/2000/svg" height="100" width="100"><defs><style>.roundShape{fill:#26a7fd;}</style></defs><circle cx="50" cy="50" r="40" class="roundShape" /></svg>'); </script>

¿Existe la posibilidad de usar el color HEX con la URL de datos utf8?

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

0

Le gustaría usar encodeURIComponent() para que no haya un problema de análisis:

 document.getElementById('imgBase64').src = 'data:image/svg+xml;utf8,'+encodeURIComponent('<svg xmlns="http://www.w3.org/2000/svg" height="100" width="100"><defs><style>.roundShape{fill:#26a7fd;}</style></defs><circle cx="50" cy="50" r="40" class="roundShape" /></svg>');
 <img id='imgBase64' />

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!