Parsing data behind hash with Javascript

A small snippet of code I wrote a few minutes ago. I tried to find a function that would parse the URI so I can load the appropriate content via AJAX.. and well, after a few Google searches I found nothing. Maybe there are some better solutions, but here’s my small contribution.

function parseURI() {

	// get the URI and remove the hash
	var uri = window.location.hash.substring(1);

	// parse the data
	var elements = uri.split('&');

	// the Object that will have the data
	var data = new Object();

	// do a for loop
	for(i = 0; i < elements.length; i++) {

		// split the element to item -> value format
		var cur = elements[i].split('=');

		// append the element to the list
		data[cur[0]] = cur[1];

	}

	// return the result
	return data;

}
This entry was posted in A chunk of code and tagged , , , . Bookmark the permalink.

2 Responses to Parsing data behind hash with Javascript

  1. Hey there I only wanted to stop by and say I enjoyed reading your blog!

  2. Cool site, keep posting!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>