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

134
Views
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 answers
Answer question

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 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!