15 October 2004 11:43 AM
Javascript escape() and UTF-8
Something I came across today when dealing with Chinese languages -
the javascript escape() function only works for ASCII characters, so if you are using another language things tend to go wonky pretty quick.
The function you want to use is encodeURIComponent() which will handle Unicode quite happily.
For a bit more reading: WorldTimZone's article on UTF-8 encoding for older browsers.






Comments
Posted by Aardvark on 08 March 2006 02:39 AM
The function <a href="http://www.kanolife.com/escape/2006/03/escape-and-unescape-javascript.html">utf8Escape</a> generates a pure UTF8 escaped string and will should handle all Unicode character sets on Unicode enabled browsers. It is also fully compatible with the JavaScript "unescape" function.
Posted by Aardvark on 08 March 2006 02:41 AM
This shoud link to code.
Posted by molsen on 08 March 2006 04:26 PM
How do I compare the image that was created to the text field. Do I pass something in a hidden field? Is there an example of how this Add Comment code does the comparison? Thanks!
Posted by peter on 24 July 2006 06:52 AM
Tools on this website: http://www.webtoolkit.info/ can do the job very well.
Posted by Dev on 14 April 2007 02:49 PM
Thanks! Saved some time.
Posted by Lee Provoost on 10 May 2007 06:44 PM
Thanks a lot man! Just solved our problem and our headache... ;-) Not that easy to hunt down these kind of bugs when you're working with Ajax/JEE.
Posted by JD Kasinsky on 07 January 2008 09:53 AM
Thanks man, very usefull. The encodeURIComponent() function works perfect instead of escape()
Bye
JD
Posted by William Sutanto on 10 April 2010 12:44 AM
thanks dude, works pretty good at pdfcast.org
does it work well on cross-browsers?
Posted by Zuolin on 21 May 2010 04:29 AM
Perfect! It solves all issues using EncodeURIComponent instead of Escape and EncodeURI.
Thanks a lot
Posted by Felix on 10 August 2010 04:31 AM
Thanks!!
Posted by jual celana on 15 February 2012 06:41 PM
I was just browsing for related blog posts for my project research and I happened to discover yours. Thanks for the excellent information!