Solved

Javascript utf-8 alert in IE

Posted on 2006-06-08
21
2,680 Views
Last Modified: 2008-02-01
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 =)
0
Comment
Question by:kelvinwkw
  • 10
  • 10
21 Comments
 
LVL 30

Expert Comment

by:callrs
ID: 16867453
alert(String.fromCharCode(20837,21916,29233,36134,21495));
0
 
LVL 11

Author Comment

by:kelvinwkw
ID: 16867476
no luck for IE =(
0
 
LVL 30

Expert Comment

by:callrs
ID: 16867478
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.
<--
0
 
LVL 30

Expert Comment

by:callrs
ID: 16867485
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...
0
 
LVL 11

Author Comment

by:kelvinwkw
ID: 16867491
&#21152;&#20837;&#21916;&#29233;&#36134;&#21495;

These are the characters that will be displayed

0
 
LVL 11

Author Comment

by:kelvinwkw
ID: 16867499
oh my god ..
cant display chinese
0
 
LVL 30

Expert Comment

by:callrs
ID: 16867527
<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...
0
 
LVL 30

Expert Comment

by:callrs
ID: 16867541
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?
0
 
LVL 11

Author Comment

by:kelvinwkw
ID: 16867557
<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 =)
0
 
LVL 11

Author Comment

by:kelvinwkw
ID: 16867561
<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
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 5

Expert Comment

by:gksinghiet
ID: 16867645
Its working for me. I think you need to install the Japanise font for displaying it properly.
0
 
LVL 11

Author Comment

by:kelvinwkw
ID: 16867658
Those r chinese word =(

0
 
LVL 30

Expert Comment

by:callrs
ID: 16867699
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>
0
 
LVL 11

Author Comment

by:kelvinwkw
ID: 16867757
abcdef plus
Popups with empty boxes...
But i need it to be display as chinese characters
0
 
LVL 30

Expert Comment

by:callrs
ID: 16867804
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
0
 
LVL 11

Author Comment

by:kelvinwkw
ID: 16867812
Im with IE 6.0 =)
Will refers to the info soon..
Lunch time
0
 
LVL 30

Expert Comment

by:callrs
ID: 16867845
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.
0
 
LVL 11

Author Comment

by:kelvinwkw
ID: 16867878
0
 
LVL 30

Expert Comment

by:callrs
ID: 16867959
What operating system is it? XP? 98? 2k?
0
 
LVL 11

Author Comment

by:kelvinwkw
ID: 16867963
xp
0
 
LVL 30

Accepted Solution

by:
callrs earned 500 total points
ID: 16868021
http://support.microsoft.com/default.aspx?scid=kb;en-us;211147     INFO: Internet Explorer Script Prompts and MBCS/Unicode
"On systems running English language versions of Windows 95, Windows 98, and Windows NT...cannot handle the display and input of text in multibyte character systems, such as Japanese and Chinese....The functions alert(), prompt(), confirm(), MsgBox, and InputBox all ultimately call Win32 functions such as MessageBox(), which can only display text for the default system locale....

"This problem does not affect localized versions of Windows systems, as long as the specified language is used. In other words, Japanese text displays fine in an alert box on systems running Japanese Windows, and the IME activates for prompt dialogs. Additionally, users of Windows 2000 Multilingual User Interface Edition (MUI) can bypass this problem by installing support for the appropriate language. "

http://en.wikipedia.org/wiki/Criticisms_of_Internet_Explorer GS:alert box IE unicode     Criticism of Internet Explorer - Wikipedia, the free encyclopedia
"Internet Explorer supports the Unicode standard for multilingual text, and is therefore theoretically capable of displaying any character which is present in an installed font. In practice, Internet Explorer does not automatically choose fonts for blocks of mixed Unicode text. Characters can end up displayed as blank squares or question marks.

"Web designers must guess which appropriate fonts may be present on users' computers, and manually specify them for every change of Unicode block. In contrast, most other browsers do this automatically.

"Workarounds
To get around these problems, many web designers build websites compliant to W3C standards, and then implement workarounds or hacks to account for Internet Explorer's rendering inadequacies, or to hide advanced website features from IE. The CSS hacks are often very complicated, as they need to deal with different versions of IE on different platforms..."

----------
So, its an MS Internet Explorer BUG! Now it's not so simple as we thought it would be...but you now have the answer as to WHY you see blocks in IE but not in Netscape. You can take it from there by reading those articles & Googling for e.g.: alert box IE unicode

Here's one of 8 workarounds mentioned in the Wikipedia:
http://dean.edwards.name/IE7/           /IE7/
"IE7 is a JavaScript library to make IE behave like a standards-compliant browser. It fixes many CSS issues and makes transparent PNG work correctly under IE5 and IE6"
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now