-
-
Save PseudoNinja/fb4a274bb2d5ead05d1b to your computer and use it in GitHub Desktop.
This file contains 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
var parser = document.createElement('a'); | |
parser.href = "http://example.com:3000/pathname/?search=test#hash"; | |
(function(){ | |
parser.isLocal = (window.location.host === parser.host) ? true : false; // determine if is local url | |
parser.fullPath = parser.host + parser.pathname + parser.hash; | |
parser.params = {}; | |
// Convert query string to object | |
var split, | |
queries = parser.search.replace(/^\?/, '').split('&') | |
; | |
for (i = 0; i < queries.length; i++) { | |
split = queries[i].split('='); | |
parser.params[split[0]] = split[1]; | |
} | |
})(); | |
//parser.protocol; // => "http:" | |
//parser.hostname; // => "example.com" | |
//parser.port; // => "3000" | |
//parser.pathname; // => "/pathname/" | |
//parser.search; // => "?search=test" | |
//parser.hash; // => "#hash" | |
//parser.host; // => "example.com:3000" | |
//parser.fullPath; // => "example.com:3000/pathname/#hash" | |
//parser.isLocal; // => false | |
//parser.params; // => [object Object] { search: "test" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added support for parameters object and isLocal detection.