×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    6

    S40 Web Apps and Character Encoding

    This is the first time I try not only WebApps, but more than trivial JavaScript, so please forgive if this is a simple question:

    If I have text in my index.html and want to manipulate it using JavaScript, non-ASCII characters get messed up. They display as a square in both the emulator and the device. The same code works fine on a desktop browser, so I guess there's no fundamental non-Nokia issue I'm having with JavaScript.

    Example:

    I take the basic template from the Nokia Web Tools (where charset is set to UTF-8) and put the following into the body:
    HTML Code:
    		<p id="one">ÖÄÜ</p>
    
    		<p id="two"></p>
    Then, in the JavaScript, I do:
    Code:
    	var newtextnode = document.createTextNode(document.getElementById('one').firstChild.nodeValue);
    	document.getElementById('two').appendChild(newtextnode);
    The expected result would be
    ÖÄÜ
    ÖÄÜ
    (which is what a regular browser gives me)

    What I get in the S40 environment is:
    ÖÄÜ
    □□□

    I tried to replace the characters using HTML entities, no difference. Any ideas?

  2. #2
    Registered User
    Join Date
    Oct 2011
    Posts
    6

    Re: S40 Web Apps and Character Encoding

    Short update: The problem above occurs on a Ubuntu PC. I got access to a Windows Vista PC and tried the same; the code runs as expected (=second paragraph contains letters, not boxes) in the simulator there, but fails again when pushed to the device. So my feeling is that somewhere character encoding is undefined and just leads to different results, depending on the environment the code is executed in. My question seems to boil down to: How to set whatever is "undefined" to a clearly defined state so it works everywhere?

    A little more info about what I really want to achieve:
    I load a set of documents from the web, extract headlines H1-H4 and re-build a navigation that's better suited for S40. I cannot change the contents nor the encoding for the fetched documents (although I'm fairly certain they're all UTF-8). An early attempt worked fine, the external document displays where it should (non-ASCII characters all OK), but re-arranging the headlines by reading nodeValues and creating new textNodes from them fails in the way described above. Now I'm stuck, because the whole optimized navigation won't be of any use if the text content is broken.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    24

    Re: S40 Web Apps and Character Encoding

    Quote Originally Posted by ossi1967 View Post
    My question seems to boil down to: How to set whatever is "undefined" to a clearly defined state so it works everywhere?
    We're doomed! I've been asking about something slightly related to this. How to know what goes wrong on the server side? and noooooooooo answer from dev or representative while they keep answering other questions.

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    6

    Re: S40 Web Apps and Character Encoding

    Quote Originally Posted by ariefbayu View Post
    We're doomed! I've been asking about something slightly related to this. How to know what goes wrong on the server side? and noooooooooo answer from dev or representative while they keep answering other questions.
    Found a workaround meanwhile at least for my needs:
    I still get the text content with nodeValue, but write it back by setting innerHTML rather than appending a new text node as a child.
    Probably not elegant, but it works on all variants of the simulator and on the one and only S40 phone I have access to - so...

    (Still I'd prefer to know the reason why it failed originally and what can be done about it to get character encoding right.)

  5. #5
    Nokia Developer Moderator
    Join Date
    Jun 2008
    Location
    Tampere
    Posts
    833

    Re: S40 Web Apps and Character Encoding

    Hi,

    I made a bug report about this issue.
    I don't exactly know how you are parsing documents, but as a workaround could you use innerHTML to get the text? It seems to preserve character encoding properly.

    Br,
    Ilkka

Similar Threads

  1. character encoding
    By Madz.R in forum Symbian C++
    Replies: 1
    Last Post: 2008-11-18, 08:45
  2. Bug? Character encoding utf-8 vs iso-8859-1
    By markswanson in forum Mobile Java General
    Replies: 0
    Last Post: 2004-11-29, 21:48
  3. Chinese character encoding
    By chandlersee in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 3
    Last Post: 2004-11-11, 13:04
  4. Character Encoding
    By law1603 in forum Mobile Java General
    Replies: 0
    Last Post: 2004-07-02, 06:06
  5. Character encoding
    By kakoulis in forum Mobile Java General
    Replies: 5
    Last Post: 2004-07-02, 06:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •