Media Ignite is a full service design, development, and marketing company based in Ottawa, Ontario, Canada.

jQuery and the URL

Posted: June 7th, 2011 | Author: Jason Fournier | Filed under: Development | Tags: , , | No Comments »

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.

Example:

http://www.hellophoto.ca/find/username

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);

console.log(mySeg);

This will output ‘username’.  Sweet.

To include the plugin in your page you could use the following:

<script type=”text/javascript” src=”js/jquery.url.min.js”></script>

A comprehensive plugin that handles the URL very well.  Check it out.



Leave a Reply