Skip to content

Instantly share code, notes, and snippets.

@mrclay
Created February 16, 2012 21:01
Show Gist options
  • Save mrclay/1847816 to your computer and use it in GitHub Desktop.
Save mrclay/1847816 to your computer and use it in GitHub Desktop.
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
Copy link

What is UFCOE? Is that a global object?

@mrclay
Copy link
Author

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