The query strings in my ASP.NET MVC are formatted like this: http://mysite.com/blog/tag/my-tag, instead of http://mysite.com/blog/?tag=my-tag, I need to extract the "my-tag" bit out of the URL, how could I accomplish that with jQuery on document loaded?
2 Answers
No need to use jQuery for that:
var tag = window.location.href.split('/').pop();
3 Comments
Martin Jespersen
or slightly faster: location.href.split('/').pop();
Saxman
One quick question: How do I get the last two parameter, such as:
http://mysite.com/date/2011/01, I need to grab the 2011 and 01? Thanks again.lonesomeday
@Saxman
location.href.split('/') will give you an array of the parts of the URL. Use normal array manipulation techniques to get what you need.