I found another question to help me find out if a string starts with another string here. I used Mark Byers answer.
However, I ran into a problem using this. For some reason it's not finding the string and returning -1
.
var response = doWork();
alert(response.lastIndexOf('/apex', 0));
if (response.lastIndexOf('/apex', 0) === 0)
window.location.href = response;
else
alert('test' + response + 'test');
The comparison returns -1
, but the alert at the end returns test/apex/IFE__IFE_ViewQuote?Id=a01i000000XobwRAARtest
. Am I doing something wrong?
I added a test to fire AFTER the above:
var response2 = '/apex/IFE__IFE_ViewQuote?Id=a01i000000Xoc4tAAB';
alert('index = ' + response2.lastIndexOf('/apex', 0));
This returned "index = 0".