-1
var id = data.rslt;
var element = id.attr("crawlLocation");
if (element.indexOf("\\") != -1){
var toSearch = element.substring(0,element.lastIndexOf("\\"));
toSearch = "\"" + toSearch + "\"";
}
var stringContent = getInnerHTML('selectedCustodiansForIngestDiv');
if(stringContent.indexOf(toSearch) == -1){
  //This loop works fine on Firefox but not in IE8
}

function getInnerHTML(elmtId) {
var innerHTML = "";
if ($gElem(elmtId) != null) {
    innerHTML = document.getElementById(elmtId).innerHTML;
}
return innerHTML;
}

In the above code, the if condition with the indexOf method is not working as expected with IE8, but works fine with other browsers.

In IE8, even if the content in toSearch is found in the string stringContent, it goes inside the loop.

I am not sure whether the problem is with indexOf method or somewhere else in my code. Let me know a way to fix this! Thanks!

UPDATE

I just noticed on debugging that in IE, the toSearch variable is appearing as "\"D:\company\"" instead of "D:\company"(In mozilla and other browsers).

Any idea to overcome this?

LGAP
  • 2,365
  • 17
  • 50
  • 71

1 Answers1

1

As you can see on this compatibility table it's not available in IE8.

You can take a RegEx to account or see the fallbacks from MDN for:

dan-lee
  • 14,365
  • 5
  • 52
  • 77
  • I tried pasting the indexOf implementation to the beginning of my script. But it didnt work even then. – LGAP Feb 04 '13 at 08:47
  • how to do this with regex? – LGAP Feb 04 '13 at 08:48
  • See this: [Is there a version of JavaScript's String.indexOf() that allows for regular expressions?](http://stackoverflow.com/a/274094/612202) – dan-lee Feb 04 '13 at 08:52
  • Added this too `regexIndexOf`. No change in the results. – LGAP Feb 04 '13 at 09:01
  • I can't reproduce this as I don't have IE 8. But with the right usage it should work (19 upvotes and an accept speak for themselves) – dan-lee Feb 04 '13 at 09:13
  • `if(stringContent.regexIndexOf(toSearch, 0) == -1){}` Is this correct after adding that regexIndexOf proptotype? – LGAP Feb 04 '13 at 09:22
  • `element.indexOf("\\") != -1` should be replaced by `element.indexOf(/\\/) != -1` (as it is a handled as a RegEx). The other occurences should also be replaced. – dan-lee Feb 04 '13 at 09:39
  • I just noticed on debugging that in IE, the `toSearch` variable is appearing as "\"D:\\exterro\"" instead of "D:\\exterro" – LGAP Feb 04 '13 at 09:49
  • Thats why its not finding the content. Any solution for this? – LGAP Feb 04 '13 at 09:50