Sign in to follow this  

[web] UTF-8 encoding, HTML and JS

This topic is 4693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am currently working on somebody's web site, and I need to be able to output Romanian UNICODE characters. I do have the references for those characters, and the &#stuff; references do display the data correctly in html. My problem is that I have to display some text on a mouse-over-button event, and that text is displayed using a javascript script which prints the &stuff; reference instead of the character it is meant to represent. Jow do I type thes characters in? I can't think of a single windows UTF-8 editor, and even if I did, I don't know how to create the characters using a non-romanian keyboard. And also, will a file in UTF-8 be parsed by a web browser as UTF-8 if it has been saved (encoded) that way?

Share this post


Link to post
Share on other sites
HTML entities are bad practise/evil, enter the Unicode characters instead.

I use Vim to do it where I can press Ctrl-v u and then enter the unicode code for the character, I assume you have the numbers for the characters, otherwise it's pretty easy to look them up in the Unicode standard if you are good at characters.

If you can't enter them any way, just enter the bytes that the characters consist of, I think that's in the Unicode standard too.

To make sure that the webbrowser parses it as UTF-8, set the encoding in the XML header to UTF-8 along with the Content-Type in the XHTML header.


<?xml version="1.1" encoding="UTF-8" ?>

<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8">




--edit--

application/xml+xhtml -> application/xhtml+xml

[Edited by - Leffe on February 10, 2005 6:17:55 AM]

Share this post


Link to post
Share on other sites
Quote:
Jow do I type thes characters in? I can't think of a single windows UTF-8 editor, and even if I did, I don't know how to create the characters using a non-romanian keyboard.

Notepad2 is a good editor with UTF-8 support. To create the characters, just install the language files for the romanian language and get going. You'll take sometime to learn, but I suppose that's the best you can do [smile]

Quote:
And also, will a file in UTF-8 be parsed by a web browser as UTF-8 if it has been saved (encoded) that way?

Specify the encoding in the meta tag in the previous post.

Share this post


Link to post
Share on other sites
I know what chraracters I need to use, for instance 0x0218 but I have the following problems:

C-v u 0218
C-v u c898
C-v u 536

Neither of these inputs in vim ouput a character. The file remains empty.

Also, I've tried out emacs with the following results:

M-x ucs-insert RET c898 RET
Error : "Character can't be decoded to UCS"

M-x ucs-insert RET 0218 RET
Inserts a character, but it's an UTF-16 version. After encoding the file as UTF-8, and loading it again in emacs, the character becomes two characters.

Share this post


Link to post
Share on other sites
Hm, are you in insert mode when you enter the commands? That's what you should be. Also, the hex code is what you are supposed to type.

Maybe Vim isn't set to use UTF-8?

Hm, I have encoding set to utf-8, fileencoding set to latin-1 (hmm...) and fileencodings set to utf-8, latin-1. Those seem to be the relevant ones.

Ah, fileencoding was set because I had the help open. For files I know I've saved as UTF-8 it's set to utf-8.

^V u 0218 inserts a ? for me :) No such glyph in my font. Hm, I think I'll post one here to see what it could be on Windows some time: È*

--edit--

ELinks messed it up :(

[Edited by - Leffe on February 10, 2005 6:28:18 AM]

Share this post


Link to post
Share on other sites

This topic is 4693 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this