Reputation: 5
Currently I have some jquery which is getting some parameters from the URL by getting all required parameters after a '#' in the URL. My URL has more than one # therefore I would like it to only select the parameters from after the last # in the URL. So far I have the below (which selects all occurrences of the #). Any ideas on how I can achieve what I want?
params = url.substring(url.indexOf('#') + 1, url.length);
Many thanks
Upvotes: 0
Views: 1095
Reputation: 23791
since you want params after last #
try this
params = url.split('#');
alert(params[params.length-1]);
Upvotes: 0
Reputation: 89750
I think you need lastIndexOf()
method.
params = url.substring(url.lastIndexOf('#') + 1, url.length);
Upvotes: 3