[thelist] javascript, unicode, DOM and Mac IE5.0

Heidi Pollock heidi at phostar.com
Tue Jul 13 14:56:02 CDT 2004


I've encountered a tedious little bug and wondered if anyone had an 
explanation for it.

The bug only occurs (to my knowledge)in IE5.0 Mac, and is fixed by 5.1. 
Theoretically, I'd be inclined to ignore such a small user group as IE 5.0 
Mac users but, of course, that's exactly the browser that the client 
used--and the reason the bug came to light.

Specifically, it seems that using certain extended latin unicode escape 
characters in a javascript variable which is then used to replace (or 
append) text via any form of *.nodeValue causes extraneous additional 
characters to appear in the document.  The exact same variable does *not* 
produce this buggy effect if inserted via document.write.

In other words:

<html><head>
<script>
function testString() {
var mystring = "\u201c";
document.all('mypara').firstChild.nodeValue = mystring;
}
</script>
</head>
<body onload="javascript:testString();">

<!-- This inserts a left double quote plus two more characters -->
<p id="mypara">Replace</p>

<!-- This inserts a left double quote just fine -->
<p><script>
var mystring = "\u201c";
document.write(mystring);
</script></p>

</body></html>

I have a more complicated test page, with screen shots, set up here:
http://www.phostar.com/test/unicodebug/

Like I said, it's nothing more than a curiosity for me.  I'm using boring 
straight quotes now until I get around to redoing the dynamic components 
with php.

-- H




More information about the thelist mailing list