Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda