Web Analytics Made Easy -
StatCounter showing &#xxxx characters in javascript alert - CodingForum

Announcement

Collapse
No announcement yet.

showing &#xxxx characters in javascript alert

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • showing &#xxxx characters in javascript alert

    i have created a english/korean site using i am using struts properties file to do internationalization.

    my messages are stored in the format &#xxxx
    for example:
    text.hello=퍫&#31231

    in my html using
    <bean:message key="text.hello"/> displays correctly in my browser.

    what i need know is for javascript to be able to show &#xxxxx; , what conversion do i need or anyone has experience with this.

    i tried replacing &# with \u and remove ; but to no avail.

    alert(fixText('<bean:message key="text.hello"/>'));
    will be
    alert(fixText('퍫&#31231'));
    and javascript alert output will be just \u54123\u31231 - should be the correct korean characters...


    function fixText(theStr){
    while(true){
    if(theStr.indexOf("&#") >= 0){
    theStr = theStr.replace("&#", "\\")
    theStr = theStr.replace(";","");
    }
    else
    break;
    }
    theStr = theStr.replace("<li>","");
    theStr = theStr.replace("</li>","");
    return theStr;
    }

    >>>>

    is this possible with javascript? if so what do you guys suggest?
    please help me out.

    many thanks...

  • #2
    text.hello=퍫秿

    has been converted to korean the real values (remove space) is:

    text.hello=&# 54320; &# 91231; (dummy values only)

    Comment


    • #3
      You mean you want to output Korean characters in the alert box?
      I think the OS should support Korean characters to be able to do that.
      Glenn
      vBulletin Mods That Rock!

      Comment


      • #4
        i think it can... let's assume it can... placing \uXXXXX directly sometimes generate the correct korean characters...

        Comment


        • #5
          Try using the ascii equivelent of &

          eg: &amp;amp;#91231

          .....Willy

          Comment


          • #6
            my values is originally in &#xxxx format... placing it in alert just shows the same &#xxxx value.

            Comment


            • #7
              maybe have any idea of korean characters mapping? maybe i could just extract & map my &#xxxxx to an array of korean characters...

              just an idea... dont really know much about javascript.

              Comment


              • #8
                HTML entities in <script> tag are not parsed the same way as in html document. Displaying language-specific characters in the alert box is, AFAIK, subjected to Input Locale setting of the OS because alert boxes are OS controls.
                Glenn
                vBulletin Mods That Rock!

                Comment


                • #9
                  Hmm, you have to do a conversion.

                  HTML: &amp;#d; or &amp;#xh;
                  JavaScrip&#116;: '\uh' or String.fromCharCode(d)
                  Last edited by liorean; Mar 8, 2004, 07:47 AM.
                  liorean <[[email protected]]>
                  Articles: RegEx evolt wsabstract , Named Arguments
                  Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
                  Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

                  Comment


                  • #10
                    i believe String.fromCharcode(d) might really work. now my problem is how do i parse a string of &#xxx;&#xxxx, extracting the values in between '&#' and ';'.

                    thx a lot...

                    Comment


                    • #11
                      Have you tried this first if this displays characters correctly?

                      alert(String.fromCharCode(54320))
                      Glenn
                      vBulletin Mods That Rock!

                      Comment


                      • #12
                        yup it worked. thanks a lot. what i need now is how to parse the strings to extract the decimal part of &#xxxx;&#xxxxx; and build a new string for display.

                        how do i extract decimal values in between '&#' and ';' in javascript ( i.e. str='&#xxxxx;&#xxxxx;')

                        please help me out on the parsing...

                        thanks a lot everyone...
                        Last edited by nys_cyber01; Mar 8, 2004, 09:46 PM.

                        Comment


                        • #13
                          Are all characters in the string Korean characters (no Roman characters at all)?

                          i.e. no instance of this:
                          text.hello="&#xxxxx; some roman characters blah blah &#xxxxx;"
                          Last edited by glenngv; Mar 8, 2004, 10:16 PM.
                          Glenn
                          vBulletin Mods That Rock!

                          Comment


                          • #14
                            Ok, assuming all Korean characters

                            Try:
                            Code:
                            function fixText(s){
                              if (!s) return '';
                              var arr = s.split('&#').join('').split(';');
                              var s2='';
                              for (var i=0;i<arr.length-1;i++){ //ignore last element, it's empty
                                s2+=String.fromCharCode(arr[i]);
                              }
                              return s2;
                            }
                            alert(fixText('&[color=black]#[/color]54320;&[color=black]#[/color]91231;&[color=black]#[/color]54320;&[color=black]#[/color]54320;'));
                            Glenn
                            vBulletin Mods That Rock!

                            Comment


                            • #15
                              it's working now. just a little modification i think. my text can be a combination of my(&#xxxxx;&#xxxxx . it still should be able to display the other characters.

                              thanks again. i can now see the light...

                              Comment

                              Working...
                              X