Skip to content

Instantly share code, notes, and snippets.

@disnet
Created March 21, 2016 21:14
Show Gist options
  • Save disnet/289f113e368f1bfb06f3 to your computer and use it in GitHub Desktop.
Save disnet/289f113e368f1bfb06f3 to your computer and use it in GitHub Desktop.
handle url parsing in IE
// the web is crazy
// http://stackoverflow.com/questions/736513/how-do-i-parse-a-url-into-hostname-and-path-in-javascript
function getLocation(href) {
var location = document.createElement("a");
location.href = href;
// IE doesn't populate all link properties when setting .href with a relative URL,
// however .href will return an absolute URL which then can be used on itself
// to populate these additional fields.
if (location.host == "") {
location.href = location.href;
}
return location;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment