[Javascript] Charset or convert characters

liorean liorean at gmail.com
Tue May 30 15:02:05 CDT 2006


On 30/05/06, Jonas Rosling <webmaster at gamearena.se> wrote:
> Is there any way in JS to set any character encodings to text that shell be
> displayed in dialogs for example? Or is there any way to convert it?

JavaScript is entirely Unicode. The source code is parsed into
Unicode, and all characters in strings are Unicode. Try using
str=String.fromCharCode(charcode) or charcode=str.charCodeAt() and
you'll see JavaScript handles international characters just fine.

> I keep having problems with displaying none international characters like å,
> ä and ö.

My guess would be that your problem lies with what encoding you're
using for your JavaScript source files. Try saving them as UTF-8
(using an editor that allows you to change the encoding of course),
and make sure your server is configured to serve them using the
'application/ecmascript; charset=utf-8' content type or possibly
'application/x-javascript; charset=utf-8'.
-- 
David "liorean" Andersson
<uri:http://liorean.web-graphics.com/>



More information about the Javascript mailing list