Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it true that IE7 doesnt support indexOf javascript? [duplicate]

Possible Duplicate:
.indexOf function on an array not working in IE7/8 using JavaScript

Im developing for IE7 and have some troubles with the javascript function indexOf.

After browsing some sites I read that IE7 doesnt support indexOf. Is this correct, and if so, whats the easiest way to check if a string contains a given string?

var test = window.location.toString();
test = test.toLowerCase();
var idString = "28A3CASDGAGHTSDASF34134";
idString = idString.toLowerCase();
if(test.indexOf(idString) > 0){
  alert('worked');
}

Edit: Most likely some coding error by myself

like image 591
matskn Avatar asked May 09 '11 13:05

matskn


People also ask

What does indexOf do JavaScript?

indexOf() The indexOf() method, given one argument: a substring to search for, searches the entire calling string, and returns the index of the first occurrence of the specified substring.

Does indexOf start at 0?

JavaScript String indexOf() It returns -1 if the str does not contain the substr . The fromIndex is an optional parameter that specifies the index at which the search starts. It defaults to zero (0), meaning that if you omit the fromIndex , the search will start from the beginning of the string.

Why is indexOf returning?

The indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.


1 Answers

As far as I'm aware, Array.indexOf isn't supported, however String.indexOf, as per your example above, is.

The best way to work things like this out are to just try them in the browser you're querying. This is much more reliable than asking someone else, people have different browser configurations etc.

Update: See this MSDN documentation page about indexOf, it's been supported since IE6.

like image 115
Rudi Visser Avatar answered Oct 05 '22 11:10

Rudi Visser