I am currently working on a JavaScript function that opens the user's email client with pre-filled content.
However, I am facing difficulties in converting special characters so they display correctly in the email client (especially when passed through a URL).
After writing a function and using console.log()
, it seems that the character conversion is not happening properly (possibly due to attempting to replace a char
with a string
).
function url_encode(item)
{
for (i in item)
{
a = item[i]
switch (a)
{
case "À": a='%C0';
break;
case "È": a='%C8';
break;
case "É": a='%C9';
break;
case "Ê": a='%CA';
break;
case "à": a='%E0';
break;
case "è": a='%E8';
break;
case "é": a='%E9';
break;
case "ê": a='%EA';
break;
case "ë": a='%EB';
break;
}
item[i] = a;
console.log(item[i])
}
return item;
}
If anyone has discovered a successful method or has any insights (or solutions) on why this may not be functioning as expected, please share!
Edit: The encodeURI
function does not correctly handle é
and è
characters (commonly used in French), resulting in é
and è
.