Created
February 16, 2012 21:01
-
-
Save mrclay/1847816 to your computer and use it in GitHub Desktop.
Parse a URI using the browser's DOM
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
(function (w, d) { | |
var a, k = 'protocol hostname host pathname port search hash href'.split(' '); | |
w.UFCOE = w.UFCOE || {}; | |
/** | |
* Parse a URI, returning an object similar to Location | |
* | |
* Usage: UFCOE.parseUri("hello?search#hash").search -> "?search" | |
* | |
* @param String url | |
* @return Object | |
*/ | |
w.UFCOE.parseUri = function (url) { | |
a || (a = d.createElement('a')); | |
// Let browser do the work | |
a.href = url; | |
for (var r = {}, i = 0; i<8; i++) { | |
r[k[i]] = a[k[i]]; | |
} | |
r.toString = function() { return a.href; }; | |
r.requestUri = r.pathname + r.search; | |
return r; | |
}; | |
})(window, document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just a namespace for UF College of Ed