Question

i have this situation:

if (image.indexOf("/bob/") != -1 || image.indexOf("/grabs/") != -1 || image.indexOf("/") == image.lastIndexOf("/")) {
    alert('success');
}

in IE8 i get Object doesn't support property or method 'indexOf'

i could probably use something like $.inArray("/bob/", image), but im not sure about lastIndexOf

any ideas how can i solve this?

Était-ce utile?

La solution

Try using a regex, something like

if(/\/(bob|ginger|grabs)\//.test(image) || /^[^\/]*\/$/.test(image)){
}

Autres conseils

If you want to solve it with jQuery, you could do

$.inArray("/", image, $.inArray("/", image)) === -1

i.e. look for the next occurrence of / after the first occurrence. This assumes that / is always present in the array. If not, then the equivalent would be

var index =  $.inArray("/", image);
if (.... || (index === -1 ||  $.inArray("/", image, index) === -1)) {
   // ...
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top