display problem of UTF-8 characters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    display problem of UTF-8 characters

    Hi,

    I want to display some Unicode Entities (arond U+2650, some graphical symbols) but I can’t get them to display in the browser (tested FF, Safari)

    what I have:
    .html file (utf-8 encoded)
    .js file (utf-8 encoded)

    insert:
    Code:
    obj.symbol = "♜";
    // somewhere later in the code
    [I]element[/I].innerHTML = obj.symbol;
    now what happens is that the symbol is converted into an Unicode char (I can text select one single char) and inserted into the HTML, but there is no visibility (besides that I can select it...).

    ex. "♜"

    strangely enough, if I select and copy-paste the text into my editor, I get the character as if nothing had happened. ah, yes, and of course the ACSII and ISO range values all work (e.g. 252).

    if I use
    Code:
    obj.symbol = "&#9820";
    // somewhere later in the code
    [I]element[/I].innerHTML = obj.symbol;
    I get displayed "&#9820 ;" i.e. the symbol string is not converted at all.

    there’s (possibly) one kind of solution, though. MDC has a String.fromChar Code() fix for UTF-16. it could work for multibytes as well (if you change the base values … which I don’t know).

    can anyone help me fix that problem?

    thanks
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    just tested the following in 3.5.5pre on ubuntu ... which worked and displayed the symbol seamlessly:

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function setSymbol(val, nodeId) {
        var node = document.getElementById(nodeId);
        node.innerHTML = val;
    }
    </script>
    <body>
    <div id="foo"></div>
    
    <input type="button" value="setSymbol" onclick="setSymbol('&#9820', 'foo')"/>
    
    </body>
    </html>
    may be i didn't get the problem quite well?

    kind regards

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      didn’t work at first either, until I changed to some rather unusual font* (I already tried Georgia, Verdana, Tahoma, … with no luck)

      * - MS Gothic

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        so with MS Gothic it worked?

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          Originally posted by gits
          so with MS Gothic it worked?
          strange, but yes. seems that the “normal” webfonts do not have glyphs in that specific Unicode range.

          Comment

          Working...