Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
how to force UTF8 into a link A with data content?

with a 100% client side, i wish to provide a text file (ics calendar by example) to my user.

i managed to process the entire code but the download file is in ISO and i wish it was in utf8 (because ical/ics charset must be utf8).

what did i miss to force the utf8 ? i put the META and the charset but the downloaded file remains in ISO charset, i don't understand why.

here my little sample to test , you can copy/paste into a new textfile to run it:

<html>
<head>
<meta charset="utf-8">
<META http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<div><a id="mylinkICS" download='my_own_agenda' class='mylinkICS'> [ CLICK HERE TO DOWLOAD your agenda ]</a></div>
</body>

<script>
var mybigstring="BEGIN:VEVENT\nUID:me@google.com\nDTSTAMP:20120315T170000Z\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:me@gmail.com\nORGANIZER;CN=Me:MAILTO::me@gmail.com
\nDTSTART:9:30am\nDTEND:10:30am\nSUMMARY:étudiant accentué \nEND:VEVENT";

var icsMSG="BEGIN:VCALENDAR\nVERSION:2.0\nX-WR-CALNAME:EDT test\nNAME:Emploi du temps test\nPRODID:ENT-test\nCALSCALE:GREGORIAN\nMETHOD:PUBLISH\nX-WR-TIMEZONE:Europe/Paris\nX-WR-CALDESC:description agenda\n";

icsMSG=icsMSG + mybigstring;
icsMSG=icsMSG + "END:VCALENDAR";
icsMSG="data:text/calendar;charset=utf8," + escape(icsMSG);
//jquery version $(".mylinkICS").attr("href", icsMSG);
document.getElementById("mylinkICS").href=icsMSG;  //dom version
</script>

</html>

in my content (stored in mybigstring var), i add accented word "étudiant accentué" . so when you download the file, you can see the accents are not showned in utf8 because the file is ISO..... i don't understand why....

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

since time passed, i found the answer : escape() function send iso charset so i used encodeURIComponent

i replaced

icsMSG="data:text/calendar;charset=utf8," + escape(icsMSG);

by

icsMSG="data:text/calendar;charset=utf8," + encodeURIComponent(icsMSG);

now, the stream is utf8 and work fine to post ics ical by this way.

Problem solved!

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda