Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-21-2012, 03:13 AM   PM User | #1
anotherJEK
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: 150
Thanks: 41
Thanked 1 Time in 1 Post
anotherJEK is an unknown quantity at this point
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 
      }
   }
anotherJEK is offline   Reply With Quote
Old 09-21-2012, 03:25 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,994 Times in 3,963 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 09-21-2012, 03:28 AM   PM User | #3
anotherJEK
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: 150
Thanks: 41
Thanked 1 Time in 1 Post
anotherJEK is an unknown quantity at this point
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.
anotherJEK is offline   Reply With Quote
Old 09-21-2012, 03:47 AM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
thanks for the info. IE8 returns undefined, too, fwiw
xelawho is offline   Reply With Quote
Old 09-21-2012, 04:27 AM   PM User | #5
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,763
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
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?
jmrker is offline   Reply With Quote
Old 09-21-2012, 04:57 AM   PM User | #6
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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.
xelawho is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:22 PM.


Advertisement
Log in to turn off these ads.