S
stephen.cunliffe
I hope the subject doesn't get escaped, but I'll try to clarify here...
I have:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
in my head (and yes, I need to keep it UTF-8...)
But I have JavaScript (external file), that creates a node, and inserts
text in it...
foo.appendChild(document.createTextNode('Hello World'));
This works fine, as long as the characters are "normal"... if I try and
add a chevron («)for example, it won't work, no matter how I escape
it.
I can however, copy another node's value (rendered elsewhere on the
page), and insert it, and it works fine.
Long story short, other than my "hacky" solution above, how do I do
this?
I've attached some sample files below (again, I hope they don't get
escaped)...
Cheers,
Steve
::::: test.html start :::::
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
</title>
<script src="foo.js"></script>
</head>
<body onload="doit();">
World
<br/>
Chevron Left <span id="CHEVRON_LEFT">«</span>
<br/>
Chevron Right <span id="CHEVRON_RIGHT">»</span>
</body>
</html>
::::: test.html end :::::
::::: foo.js start :::::
function doit(){
var bar = document.getElementsByTagName('body')[0];
var CHEV_LEFT = document.getElementById('CHEVRON_LEFT');
var CHEV_RIGHT = document.getElementById('CHEVRON_RIGHT');
bar.appendChild(document.createTextNode('qwerqwerqwerqw'));
bar.appendChild(document.createTextNode('GGGG »asdfasdf« HHHH
U+00BB HHH' + CHEV_LEFT.firstChild.nodeValue + ' ' +
CHEV_RIGHT.firstChild.nodeValue));
}
::::: foo.js end :::::
I have:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
in my head (and yes, I need to keep it UTF-8...)
But I have JavaScript (external file), that creates a node, and inserts
text in it...
foo.appendChild(document.createTextNode('Hello World'));
This works fine, as long as the characters are "normal"... if I try and
add a chevron («)for example, it won't work, no matter how I escape
it.
I can however, copy another node's value (rendered elsewhere on the
page), and insert it, and it works fine.
Long story short, other than my "hacky" solution above, how do I do
this?
I've attached some sample files below (again, I hope they don't get
escaped)...
Cheers,
Steve
::::: test.html start :::::
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>
</title>
<script src="foo.js"></script>
</head>
<body onload="doit();">
World
<br/>
Chevron Left <span id="CHEVRON_LEFT">«</span>
<br/>
Chevron Right <span id="CHEVRON_RIGHT">»</span>
</body>
</html>
::::: test.html end :::::
::::: foo.js start :::::
function doit(){
var bar = document.getElementsByTagName('body')[0];
var CHEV_LEFT = document.getElementById('CHEVRON_LEFT');
var CHEV_RIGHT = document.getElementById('CHEVRON_RIGHT');
bar.appendChild(document.createTextNode('qwerqwerqwerqw'));
bar.appendChild(document.createTextNode('GGGG »asdfasdf« HHHH
U+00BB HHH' + CHEV_LEFT.firstChild.nodeValue + ' ' +
CHEV_RIGHT.firstChild.nodeValue));
}
::::: foo.js end :::::