I was recently working on a side project, www.hellophoto.ca, and found myself needing segments of the URL in an effort to build a RESTful service. Through a combination of .htaccess and this jQuery URL plugin I was able to easily grab portions of the URL. The plugin covers URL attributes, Query String Parameters, URL Segments, and Fragment Parameters. All great stuff.
Create a URL object:
var url = $.url();
Use one of the methods for accessing the information you need. Say, for instance, I want to know the username of the URL. I would do the following:
var mySeg = url.segment(-1);
This will output ‘username’. Sweet.
To include the plugin in your page you could use the following:
A comprehensive plugin that handles the URL very well. Check it out.