1

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 2

2

No need to use jQuery for that:

var tag = window.location.href.split('/').pop();
Sign up to request clarification or add additional context in comments.

3 Comments

or slightly faster: location.href.split('/').pop();
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.
@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.
0

Try This:

document.location.toString().match('.*/(.*)$')[1]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.