Created
December 6, 2014 00:33
-
-
Save jayphelps/952b68c49d7e2aa4cc77 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 parseLocation = (function () { | |
var a = document.createElement('a'); | |
function parseLocation(url) { | |
a.href = url; | |
var protocol = (!a.protocol || a.protocol === ':') ? location.protocol : a.protocol; | |
// IE8 inconsistently returns leading slash | |
var pathname = (a.pathname.match(/^\//)) ? a.pathname : '/' + a.pathname; | |
return { | |
hash: a.hash, | |
host: a.host || location.host, | |
hostname: a.hostname || location.hostname, | |
href: a.href, | |
pathname: pathname, | |
port: a.port || location.port, | |
protocol: protocol, | |
search: a.search | |
}; | |
} | |
return parseLocation; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment