简体   繁体   中英

JavaScript with Internet Explorer 8

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?

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM