Skip to content

Instantly share code, notes, and snippets.

@os0x
Created March 12, 2009 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save os0x/77946 to your computer and use it in GitHub Desktop.
Save os0x/77946 to your computer and use it in GitHub Desktop.
function URI(uri,base){
var a, _loc = location, self = this;
if (base) {//via nanto_vi
var XHTML_NS = "http://www.w3.org/1999/xhtml";
var XML_NS = "http://www.w3.org/XML/1998/namespace";
a = document.createElementNS(XHTML_NS, 'a');
a.setAttributeNS(XML_NS, 'xml:base', base);
} else if (URI.cache) {
a = URI.cache;
} else {
a = URI.cache = document.createElement('a');
}
a.href = uri;
for (var k in _loc)
if (a[k] !== void 0)
this[k] = a[k];
}
URI.prototype.toString = function(){
return this.href;
};
URI.prototype.get_param = function(){
if (this.param) return this.param;
var res = {}, keys = [], values = [];
this.search.substring(1).split('&').forEach(function(q){
var p = q.split('=');
res[p[0]] = p[1];
keys.push(p[0]);
values.push(p[1]);
});
return (this.param = {hash:res,keys:keys,values:values});
};
//var u=new URI('../hoge?a=2&d=4','http://ss-o.net/test/');
//console.log(u, u.get_param());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment