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