Link to home
Start Free TrialLog in
Avatar of blcott
blcott

asked on

Chinese characters appearing as boxes in Javascript alert boxes

I am trying to get chinese characters to display in my alert message box using javascript. On my XP machine everything displays properly, Chinese in the html and in the javascript dialog boxes. On my windows 2000 machine, the chinese characters in the html is displaying properly, but the chinese characters in the javascript dialog boxes appear as "boxes".

My HTML page is set to use charset="utf-8". The chinese characters are displaying perfectly on the web page itself.

Does this have something to do with the browser and the Javascript version it supports?

sample:

<script LANGUAGE="JavaScript" TYPE="text/javascript">

alert("&#27492;&#27979;&#35797;&#33021;&#22815;&#26816;&#27979;&#34394;&#20551;&#21644;&#22840;&#22823;&#30340;&#22238;&#31572;&#12290; \n\n &#38750;&#30495;&#23454;&#31572;&#26696;&#65292;&#21017;&#20320;&#30340;&#27979;&#35797;&#32467;&#26524;&#26080;&#25928;");

</script>


Avatar of blcott
blcott

ASKER

In the above question, I actually pasted chinese characters, not the numbers shown. I don't know why it shows the decimal equivalent to the chinese character in the example above.
try using that javascript above to display you characters on your page. that should work fine.
An interesting problem.  I have a very recent version of IE on my Windows 2000 machine and have the same problem.

Accorsing to IBM's globalisation tips alert(), confirm(), and prompt() functions in some browsers are just not capable of showing utf-8 encoded characters.
http://publib.boulder.ibm.com/infocenter/wchelp/v5r6/index.jsp?topic=/com.ibm.commerce.developer.doc/refs/rgbtips.htm

I notice there is no problem with Firefox on the same machine.  I have IE 6.0.2800.1106 here.  I can check later what version of IE is on my XP box.
Avatar of blcott

ASKER

maclema,

Taking those decimal characters in my example above, as you suggest, does not work. The js dialog displays exactly that, the decimal characters.

blcott
try


var temp = document.createElement('div')
temp.innerHTML = "&#27492;&#27979;&#35797;&#33021;&#22815;&#26816;&#27979;&#34394;&#20551;&#21644;&#22840;&#22823;&#30340;&#22238;&#31572;&#12290; \n\n &#38750;&#30495;&#23454;&#31572;&#26696;&#65292;&#21017;&#20320;&#30340;&#27979;&#35797;&#32467;&#26524;&#26080;&#25928;"

alert(temp.innerHTML)
could it be that your win2000 simply has not a unicode font installed? i also know that TAHOMA.TTF on win2000 contains quite less characters than the one coming with XP. this font file is VERY HUGE and since the display boxes from MSIE dont really rely on the capability of html compatibility but instead on the ones of the system itself, i guess its simply an issue of the regional settings.

try microsoft.com for downloading the most recent unicode TAHOMA.TTF (or copy it from XP, then go into the fonts folder on 2K and select "install font"). im sure thats the "problem"
Avatar of blcott

ASKER

dynamicrevolutions and AmigoJack

None of your solutions work. Again on w2k with IE 6.0 the page displays the simplified characters fine but the javascript dialog box contains "boxes". I have FireFox 5.0 on the same machine and everthing displays properly, characters on page and characters in js dialog box.

This is the only question I have ever posted on this site that there doesn't seem to be anyone with a solution. That is amazing!
did you check start -> control panel -> regional settings -> languages -> additional language support (complex letters, right to left, east asian)? firefox displays messageboxes itself (on its own support), while MSIE uses standard windows functions instead - so it must be a problem dealing with win2k
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have had the same issue.  I had the language pack installed (simplified Chinese language pack) from Microsoft's site.  The characters on the web page would look fine (using unicode) characters, but when the same characters were put in an alert box it would just display sqaures.  I fixed this by installing the "East Asian languages" in windows.  For Windows XP, open the control panel and double click on "regional and language options"  Then on the "language" tab click the check box that is labeled "Install files for East Asian Languages".  That seemed to fix it for me.
Thanks,
Jeff Beard-Shouse
Business Software Group at Motorola