I tried like this when handling chinese, but the output is messy code garbled:
var a = "你好";
undefined
a
"你好"
a = unescape(encodeURIComponent(a));
"ä½ å¥½"
a
"ä½ å¥½"
compared to handling English:
var a = "Hello";
undefined
a
"Hello"
a = unescape(encodeURIComponent(a));
"Hello"
Here is my whole code:
var content = $("div#test").html();
content = unescape(encodeURIComponent( content ));
content = window.btoa(content);
content = "data:image/svg+xml;filename:{{ request.session.access_token.uid }}.svg;base64," + content;
UPDATED:
What I am trying to do is encoding a generated SVG as data url for user to download. I solved this problem by converting SVG to canvas (using CanVG) first and use html2canvas to generate base64 ... finally it works ...
decodeURIComponent(escape(unescape(encodeURIComponent("東京")))) "東京"
, even thought the intermediate result looks like funny characters--because it IS funny characters.