IE6 SP1 workaround?

A

Adam Warner

Hi all,

Can someone please explain why the HTML below prints >< in Microsoft
Internet Explorer 6 SP1 (at least on the machine I tested) instead of
41 42 43 <? Active scripting is enabled.

Thanks,
Adam

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><title>Titles are Mandatory</title></head>
<body>
<script type="text/javascript">
function test() {
s="ABC";
for (c in s) {
document.write(s.charCodeAt(c).toString(16)+" "); }}
</script>
&gt;<script type="text/javascript">test();</script>&lt;
</body>
</html>
 
R

Richard Cornford

Adam said:
Can someone please explain why the HTML below prints
on the machine I tested) instead of >41 42 43 <?
Active scripting is enabled.
<script type="text/javascript">
function test() {
s="ABC";
for (c in s) {
<snip>

Here - s - is a string. The - for (prop in obj) - statement will
type-convert - s - into an object. That object is a String object. By
specification String objects do not have properties that index the
characters in the string (though Mozilla's strings are implemented that
way, but there is still no reason to expect such properties to be
enumerable even if implemented).

try:-

var s = new String("ABC");
for( var c = 0; c < s.length;c++){
document.write(s.charCodeAt(c).toString(16)+" ");
}

And do remember to use the - var - keyword within functions to make
variables that do not need to be global into local variables.

Richard.
 
A

Adam Warner

Hi Richard Cornford,
Here - s - is a string. The - for (prop in obj) - statement will
type-convert - s - into an object. That object is a String object. By
specification String objects do not have properties that index the
characters in the string (though Mozilla's strings are implemented that
way, but there is still no reason to expect such properties to be
enumerable even if implemented).

Brilliant. Thanks Richard and mscir. I got into this mess because I tried
iterating over the characters in the string (indeed using Mozilla) and was
surprised to find the iterating variable was bound to the index of the
character instead of the character itself. So you can see what I did next :)
And do remember to use the - var - keyword within functions to make
variables that do not need to be global into local variables.

A very helpful tip. I'm well versed in Common Lisp so I merely have to
learn all the unfortunate deviations :)

Regards,
Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top