Created
March 12, 2009 06:50
-
-
Save os0x/77946 to your computer and use it in GitHub Desktop.
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 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