469,336 Members | 5,440 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

IE6 SP1 workaround?

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>

Jul 23 '05 #1
3 1149
Adam Warner wrote:
<snip>
<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;


How about this approach:
<head>
<script type="text/javascript">
function test(s){
for (var c=0; c<s.length;c++)
document.write(s.charCodeAt(c).toString(16)+" ");
}
</script>
</head>

&gt;<script type="text/javascript">test('ABC');</script>&lt;
Jul 23 '05 #2
Adam Warner wrote:
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.

<snip> <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.
Jul 23 '05 #3
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
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by klappnase | last post: by
reply views Thread by Jonas Smithson | last post: by
7 posts views Thread by Justin Shen | last post: by
1 post views Thread by slyi | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.