[Javascript] Encoding Unicode characters in HTML
Sheriff
sheriff at drivestream.com
Mon Aug 22 03:39:04 CDT 2005
>>On 8/18/05, Judah Frangipane <judah-fc at t8design.com> wrote:
>> I know how a person can encode an ampersand in html. They use "&"
>> and this code is rendered by the browser into "&".
>>
>> What I don't know is how to encode a unicode character. I am trying to
>> encode a bullet character. The keystroke is ALT+0149 as displayed here
>> ..
>The bullet character is unicode code point 8226 (2022 in hex), not
>0149. 149 is its "ASCII" value in some character encoding. Maybe ISO
>8859-1, maybe UTF-8, but maybe not. If you use • (anything over
>127) you may need to make sure you specify a character encoding for
>your page to be certain it displays correctly for browsers on all
>platforms.
When there is ASCII represention for . (Alt+0149) why go for unicode?
So it is simply: • If you are unsure about what I am talking about
surround the ASCII value of any character (say 'A' which is 65) by '&#' in
the beginning and ';' in the end. So, for A it is A
I created the following code, which I use, whenever I need to find the ASCII
for a specific character.
<script>
function gen_ascii_table(){
// Start/End Values
var init=32; // 32 is space
var end=10000;
var d=document;
d.writeln('<table>');
d.writeln(' <tr>');
d.writeln(' <th>S.No</th><th>ASCII</th><th>Character</th>');
d.writeln(' </tr>');
for(var i=init; i<=end; ++i){
d.writeln(' <tr>');
d.write(' <td align=right>' + (i-init+1) + '.</td>');
d.write(' <td>' + i + '</td>');
d.write(' <td>&#' + i + ';</td>\n'); // <td> </td> and so on
d.writeln(' </tr>');
}
d.writeln('</table>');
}
</script>
And, call this function wherever required:
<body>
<script> gen_ascii_table(); </script>
</body>
HTH :)
More information about the Javascript
mailing list