PDA

View Full Version : JavaScript character encoding?


wbing3
07-25-2005, 10:46 PM
I am working in a windows 2000 environment using JavaScript's OpenTextFile method to open a file for writing in UNICODE mode:

var fso = new ActiveXObject('Scripting.filesystemObject");
var fw = fso.OpenTextFile("myfile.txt", 2, true, -1);

How do I determine the character encoding scheme (utf-8, utf-16, etc) used by JavaScript when writing (and reading if needed) this file?

I need to know this so that I clearly communicate with a Java program that will perform character conversions on this file and return it to my JavaScript function.

Thanks,
wbing3

Kor
07-26-2005, 09:41 AM
http://www.w3.org/International/O-charset
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Unicode

Kor
07-26-2005, 01:00 PM
Javascript code text is alway encoded in UTF-16 form of Unicode and NFC. Even if the web page charset is UTF-8, ISO-8859-1, ISO-8859-2... a.s.o. the modern browsers always convert the web content into UTF-16 for internal needs.

to return the ASCII character, javascript uses the unicode escape sequence of type

\uXXXX where XXXX are the 2 hexavalues of the unicode character.

ex:
alert('\u05D0')

Anyway, I guess that u need to specify the charset, if dealing with XML doctype
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
or
<meta http-equiv="content-type" content="text/html;charset=utf-16" />

wbing3
07-26-2005, 02:20 PM
Thanks for your response!

wbing3