Created
March 21, 2016 21:14
-
-
Save disnet/289f113e368f1bfb06f3 to your computer and use it in GitHub Desktop.
handle url parsing in IE
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
// 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