Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parse a URI using the browser's DOM
(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);
@WiredAcademic

This comment has been minimized.

Copy link

@WiredAcademic WiredAcademic commented Mar 19, 2012

What is UFCOE? Is that a global object?

@mrclay

This comment has been minimized.

Copy link
Owner Author

@mrclay mrclay commented Mar 19, 2012

just a namespace for UF College of Ed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment