473,414 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Trouble with document.write and UTF-8

Can someone explain why I don't seem unable to use document.write to
produce a valid UTF-8 none breaking space sequence (Hex: C2A0) ?

I've tried everyway I've been able to find to tell the browser I'm
trying to print UTF-8 and still no luck. I'd like the first 2 tries to
match the second two tries as far as output.

<HTML>
<meta http-equiv="Content-Type" content="application/x-script;
charset=UTF-8">
<SCRIPT language="javascript" charset="UTF-8">
var out = "UTF-8 nbsp:\xC2\xA0:Unicode:\uC2A0:Unicode:\u00A0:HTML
nbsp:&nbsp;"
document.open("text/html; charset=UTF-8");
document.write(out);
var i =0;
while (i <out.length){
document.write("<br>"+i+" "+out.charAt(i)+" "+out.charCodeAt(i));
i++;
}
document.close();document.charset="UTF-8";
</SCRIPT>
</HTML>

The output looks like this:
UTF-8 nbsp:Â :Unicode:*:Unicode: :HTML nbsp:
0 U 85
1 T 84
2 F 70
3 - 45
4 8 56
5 32
6 n 110
7 b 98
8 s 115
9 p 112
10 : 58
11 Â 194
12 160
13 : 58
14 U 85
15 n 110
16 i 105
17 c 99
18 o 111
19 d 100
20 e 101
21 : 58
22 * 49824
23 : 58
24 U 85
25 n 110
26 i 105
27 c 99
28 o 111
29 d 100
30 e 101
31 : 58
32 160
33 : 58
34 H 72
35 T 84
36 M 77
37 L 76
38 32
39 n 110
40 b 98
41 s 115
42 p 112
43 : 58
44 & 38
45 n 110
46 b 98
47 s 115
48 p 112
49 ; 59

Thanks!

Nov 11 '05 #1
1 15539
st************@yahoo.com wrote:
Can someone explain why I don't seem unable to use document.write to
produce a valid UTF-8 none breaking space sequence (Hex: C2A0) ?
The Unicode 4.1 character at code point 0xC2A0 is an (unnamed) Hangul
syllable, as can be seen at <http://www.unicode.org/charts/PDF/UAC00.pdf>
I've tried everyway I've been able to find to tell the browser I'm
trying to print UTF-8 and still no luck. I'd like the first 2 tries to
match the second two tries as far as output.

<HTML>
<meta http-equiv="Content-Type" content="application/x-script;
charset=UTF-8">
Pardon? This is supposed to be an HTML document, is it not? So the basic
Content-Type should be text/html. And if that HTML document were UTF-8
encoded, you would not have to escape Unicode anyway. So you want to
change the `charset' parameter to ISO-8859-1 and the like, definitely
no UTF encoding.

And there is no known MIME-like label as 'application/x-script'.
I wonder how you got the idea.

You probably meant

<meta http-equiv="Content-Script-Type"
content="application/javascript; charset=UTF-8">

as described in the Informal RFC "Scripting Media Types", which is,
however, not yet used by user agents.
<SCRIPT language="javascript" charset="UTF-8">
The `language' attribute is deprecated in HTML4, the `type' attribute
is #REQUIRED. The `charset' attribute is for linked resources, i.e.
useful only in combination with the `src' attribute.

<script type="application/javascript">

See <http://www.w3.org/TR/html4/interact/scripts.html#edef-SCRIPT>
and <http://validator.w3.org/>.
var out = "UTF-8 nbsp:\xC2\xA0:Unicode:\uC2A0:Unicode:\u00A0:HTML
nbsp:&nbsp;"
You need to understand what UTF and Unicode are and how UTF works,
see <http://www.unicode.org/faq/>.
document.open("text/html; charset=UTF-8");
There is no specified argument for the HTMLDocument::open() method.
Therefore, Mozilla/5.0 based user agents will ignore it if you provide
one.

<https://bugzilla.mozilla.org/show_bug.cgi?id=73409>
document.charset="UTF-8";
There is no document.charset property, hence you are creating one here.
The output looks like this:
[...]


Works as designed.

Summary: You should definitely drink more tea[tm] when coding.
PointedEars
Nov 11 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Svennglenn | last post by:
I'm working on a program that is supposed to save different information to text files. Because the program is in swedish i have to use unicode text for letters. When I run the following...
0
by: Tor Hovland | last post by:
I'm trying to transform the document element of incoming xml files, however, I'm having trouble with namespace references not appearing correctly. Here's an example input file: <?xml...
1
by: Bartek | last post by:
Hello This is my problem: It consider xml 2 xml conversion. source document had unknown structure (xhtml), xslt must process every node, attribute, text, comments etc. from source and write in...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory” exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
6
by: Just Me | last post by:
Any ideas on this. I am trying to loop through an xml document to remove attributes, but Im having so much trouble, any help is appreciated //THIS IS THE EXCEPTION ( SEE CODE LINE WHERE FAILURE...
10
by: whisher | last post by:
Hi. I'm not able to understand why this simple snippet doesn't work with IE. It works fine with FF and Opera 9. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
10
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I had a program and it always works fine and suddenly it gives me the following message when a pass a xml file to our server program: error code: -1072896680 reason: XML document must...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.