Skip to content

Instantly share code, notes, and snippets.

@amaxwell01
Created June 20, 2012 23:19
Show Gist options
  • Select an option

  • Save amaxwell01/2962865 to your computer and use it in GitHub Desktop.

Select an option

Save amaxwell01/2962865 to your computer and use it in GitHub Desktop.
Retrieves the key value pairs in a URL string and places them in an object for easy look-up
/**
* Retrieves the key value pairs in a URL sring
* and places them in an object for easy lookup
*/
var parseURLString = function( string ) {
var a = document.createElement("a");
a.href = string;
//hide it from view when it is added
a.style.display = "none";
//add it
document.body.appendChild(a);
var myLocation = {};
myLocation.hash = a.hash;
myLocation.host = a.host;
myLocation.hostname = a.hostname;
myLocation.href = a.href;
myLocation.origin = a.origin;
myLocation.pathname = a.pathname;
myLocation.port = a.port;
myLocation.protocol = a.protocol;
myLocation.search = a.search;
//remove it
document.body.removeChild(a);
return myLocation;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment