Link to home
Start Free TrialLog in
Avatar of kelvinwkw
kelvinwkwFlag for Malaysia

asked on

Javascript utf-8 alert in IE

I am facing a problem whereby IE does not alert these utf-8 character probably.

Although i've add
<% Session.Codepage = 65001%>
and
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

on every single page

alert("&#21152;&#20837;&#21916;&#29233;&#36134;&#21495;");

However it works under Netscape.

Its an ASP page

Thanks =)
Avatar of callrs
callrs

alert(String.fromCharCode(20837,21916,29233,36134,21495));
Avatar of kelvinwkw

ASKER

no luck for IE =(
Quote: www.faqts.com/knowledge_base/view.phtml/aid/1621 GS:javascript unicode alert     FAQTs - Knowledge Base - View Entry - How do I get the character from the (ascii/iso/uni) char code? -->
...
JavaScript 1.2 introduced
  String.fromCharCode(characterCode)
to find the character from its ascii/iso/unicode, as in
  alert(String.fromCharCode(169))
so if you script for version 4+ browsers you don't need to custom
function given at the beginning.
You can even pass in a list of char codes e.g.
  alert(String.fromCharCode(75,105,98,111,108,111,103,121))

With JavaScript 1.3 you can also use unicode escape sequences of the
form
  '\uDDDD'
where
  DDDD
is the 4 digit hexadecimal char code value e.g.
  alert('\u00A9')
will also show the copyright symbol.
<--
kelvinwkw, I'm using IE, and I got it to work...Not the characters you want printed since I dont have the fonts you have, but the alert & String.fromCharCode DO work together...
&#21152;&#20837;&#21916;&#29233;&#36134;&#21495;

These are the characters that will be displayed

oh my god ..
cant display chinese
<html>
You should see "abc", then "def"
<script type="text/javascript">
alert(String.fromCharCode(0x61,0x62,0x63)); // alert abc
alert("\u0064\u0065\u0066"); // alert def
</script>
</html>

Copy & paste that into a notepad file, save the file as "c:\temp\test.htm" (be sure to put quotes or it may save it as test.htm.txt)
Then open the file in IE by typing: c:\temp\test.htm
You'll see 2 alets popup up

Now, you can substitute your unicode numbers the alert statements....if the above works but your characters don't, THEN YOU LIKELY NEED TO INSTALL THE FONT(S)...

Let me know if my example works (abc, def) in your IE or not, etc. It works on mine...
http://home.att.net/~jameskass/utf8ornot.htm GS:utf-8 ie 5     UTF-8 Encoding / Netscape & Internet Explorer
www.alanwood.net/unicode/explorer.html GS:utf-8 ie 5.5     Setting up Windows Internet Explorer 5, 5.5 and 6 for Multilingual and Unicode Support

What version of IE are you using?
<html>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<input type="button" value="&#21152;&#20837;&#21916;&#29233;&#36134;&#21495;" onclick="alert('&#32943;&#23450;&#21152;&#20837;&#27492;&#36134;&#21495;&#21527;?');"/>
</body>

</html>

Please try this on ur browser =)
<html>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<input type="button" value="&#21152;&#20837;&#21916;&#29233;&#36134;&#21495;" onclick="alert('&#21152;&#20837;&#21916;&#29233;&#36134;&#21495;');"/>
</body>

</html>


I think try this better
Its working for me. I think you need to install the Japanise font for displaying it properly.
Those r chinese word =(

alert('&#32943;&#23450;&#21152;&#20837;&#27492;&#36134;&#21495;&#21527;?');
Is that correct? I can't find a reference to if that is correct or not. But this should work:

alert(String.fromCharCode(32943,23450,21152,20837,27492;36134,21495;21527);
Or you can use this:
alert("\u80af\u5b9a\u52a0\u5165\u6b64\u8d26\u53f7\u5417");
but the way you got it -- it's meant for HTML and the document.write command which writes to the HTML document in your browser: the "&...;" is for HTML (see code below)

Copy & paste this into a new .htm file, and open it in IE. LET ME KNOW WHAT YOU SEE IN THE ALERT BOXES THEN. Thanks
<script type="text/javascript">
var abcdef="&#97;&#98;&#99;&#100;&#101;&#102;"
document.write(abcdef);
var x=String.fromCharCode(32943,23450,21152,20837,27492,36134,21495,21527);
var y="\u80af\u5b9a\u52a0\u5165\u6b64\u8d26\u53f7\u5417"
alert(x);
alert(y);
</script>
</script>
abcdef plus
Popups with empty boxes...
But i need it to be display as chinese characters
Then look at the last two links I gave you; search on Google for more if those links are not good enough. You apparently need to install some chinese fonts. Have you installed them?
If you have IE v5 or v5.5, there might be some problems. You havent told me yet what version of IE you are using. Are you using v 6.0?

Be sure to use either one of the two unicode syntax I've given you. Your other syntax simply wont work....


To test if you have the fonts installed: go to
http://www.macchiato.com/unicode/chart/     JavaScript Unicode Charts
And type in a unicode number and then hit Find.

Here's a link for display problems: http://www.unicode.org/help/display_problems.html
Im with IE 6.0 =)
Will refers to the info soon..
Lunch time
http://www.thdl.org/tools/chinese.html "To work with Chinese characters beyond plane 0 of the Unicode standard (Unicode CJK Extension A and B*) it is also necessary to install Microsoft's GB18030 support package**  for Windows 2000 & XP. This package includes a large (12 MB) Chinese font (SimSun18030.ttc)." http://www.microsoft.com/downloads/details.aspx?FamilyID=fc02e2e3-14bb-46c1-afee-3732d6249647&DisplayLang=en

That's all for now. Search Google for: chinese unicode fonts
etc.
I'm too beat to continue. Talk to you later.
What operating system is it? XP? 98? 2k?
xp
ASKER CERTIFIED SOLUTION
Avatar of callrs
callrs

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