Read a page's GET URL variables and return them as an associative array.
Example for URL http://www.example.com/index.html?hello=bonjour&goodevening=bonsoir
var hash = getUrlVars(); alert(hash['hello']); // prints 'bonjour' alert(hash['goodevening']); // prints 'bonsoir'
// Read a page's GET URL variables and return them as an associative array. function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for(var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; }
Comments
Subscribe to comments
You need to login to post a comment.

Great script. I also adopted it for jQuery as an extension.
So check out Getting URL parameters by name in jQuery code snippet.
Take a look here for a shorter solution: http://snipplr.com/view/19838/get-url-parameters/
Assuming that I use:
Assuming that I use:
Assuming that I use:
Sorry for the multiple posts! I just hit refresh.
My question is: How do I get the script to output to a document.write or other way to put the data to an HTML form field.
Thank you.
Works like a charm. Thanks for this code.