IE6 SP1 workaround?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam Warner

    #1

    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[color=blue]
    >41 42 43 <? Active scripting is enabled.[/color]

    Thanks,
    Adam

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head><title>Ti tles 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">tes t();</script>&lt;
    </body>
    </html>

  • mscir

    #2
    Re: IE6 SP1 workaround?

    Adam Warner wrote:
    <snip>[color=blue]
    > <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">tes t();</script>&lt;[/color]

    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">tes t('ABC');</script>&lt;

    Comment

    • Richard Cornford

      #3
      Re: IE6 SP1 workaround?

      Adam Warner wrote:[color=blue]
      > Can someone please explain why the HTML below prints[color=green]
      > >< in Microsoft Internet Explorer 6 SP1 (at least[/color]
      > on the machine I tested) instead of >41 42 43 <?
      > Active scripting is enabled.
      >[/color]
      <snip>[color=blue]
      > <script type="text/javascript">
      > function test() {
      > s="ABC";
      > for (c in s) {[/color]
      <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.


      Comment

      • Adam Warner

        #4
        Re: IE6 SP1 workaround?

        Hi Richard Cornford,
        [color=blue]
        > 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).[/color]

        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 :-)
        [color=blue]
        > And do remember to use the - var - keyword within functions to make
        > variables that do not need to be global into local variables.[/color]

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

        Regards,
        Adam

        Comment

        Working...