I have a URL string like http://www.example.com/?chicken?toast
And I want to be able to store the values after each of the ? characters.
I have it working getting the last ?value - but cant seem to store the first...
Code that works to get the last ?value is:
window.lastValue = window.location.href.substring(window.location.href.lastIndexOf('?') + 1);
This will give you an array of the values you want:
var r = window.location.href.split("?") r.shift(); console.log(r);
If there are always exactly two values, you can use this to extract them:
var val1 = r.shift(); var val2 = r.shift();