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
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
}
}
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
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.
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?
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.