Domanda

Within jQuery Address target[1] can be Films-by-Name-C7. I use the following to extract 7

(target[1].lastIndexOf('?') > 0 ?target[1].slice(0, target[1].indexOf("?")).substr((target[1].lastIndexOf('C')+1)):target[1].substr(-(target[1].length-target[1].lastIndexOf('C')-1)))

This works on all browsers except IE8. I don't know why it does this. When I try it out in Fiddle it also doesn't work. So how can i extract 7 from Films-by-Name-C7 in ie8?

È stato utile?

Soluzione

IE<9 doesn't have an .indexOf() function for Array, to define the exact spec version, run this before trying to use it:

Check this link

As you need seven this can be the solution

Altri suggerimenti

The problem with your code is the negative value of substr function

(target[1].lastIndexOf('?') > 0 ? 
    target[1].slice(0, target[1].indexOf("?")).substr((target[1].lastIndexOf('C')+1)) :
    target[1].substr(-(target[1].length - target[1].lastIndexOf('C')-1)))

The negative value of substr won't work in browsers < IE9 as per W3C standards

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top