Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    215
    Thanks
    52
    Thanked 1 Time in 1 Post

    This is info, not a question about strings

    For anyone who doesn't already realize this, I have been having trouble with
    Internet Eplorer window freezes and have traced it to the way my code was
    handling strings.
    where I used
    Code:
    // even though this will work in every other browser tested:
    var str = 'some text';
    for(var i = 0; i < str.length; i++)
       {
         if(str[i] == 's') /////<<<<<< this will freeze Internet Explorer window
          { 
            // do something 
          }
       }
    The following was the fix
    Code:
    var str = 'some text';
    for(var i = 0; i < str.length; i++)
       {
         if(str.charAt(i) == 's') /////<<<<<< This will work
          { 
            // do something 
          }
       }

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    It doesn't freeze in MSIE 9. On the other hand it doesn't work.

    If you try doing alert(str[7]); (for example), you get just "undefined".
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Location
    Now Southern Oregon. I was born and had lived my life in Los Angeles until relocating last year (2010)
    Posts
    215
    Thanks
    52
    Thanked 1 Time in 1 Post

    I was referring to IE 7

    All the testing I was doing, and bug chasing was in Internet Explorer 7. This would be a issue for backward compatibility most likely. Your info is useful as well.

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    thanks for the info. IE8 returns undefined, too, fwiw

  • #5
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,092
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Question

    Post #1 was interesting,
    but for all the observations and testing in the MSIE browsers
    what is the reason for the 'freeze' or 'undefined' messages?

    Appears to be valid and innoculus code.
    What is the underlying problem that is going on to cause this particular action?
    Why would MSIE work like this?

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,981
    Thanks
    56
    Thanked 557 Times in 554 Posts
    MDN says that str[7] is part of ECMAScript 5 but not ECMAScript 3, which I guess would explain the IE<9 thing

    I'm surprised because IE8 can return str.length correctly and I was under the impression that anything with a length could be accessed using array notation.

    But I guess not.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •