Skip to content

Instantly share code, notes, and snippets.

@jayphelps
Created December 6, 2014 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayphelps/952b68c49d7e2aa4cc77 to your computer and use it in GitHub Desktop.
Save jayphelps/952b68c49d7e2aa4cc77 to your computer and use it in GitHub Desktop.
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