Created
June 20, 2012 23:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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