|
|
|
A javascript class for retrieving query string
3
This function is quite useful in accessing the query string, host, path and filename obtained from an url. See detailed discussion in A javascript class for retrieving query string
<script type="text/javascript">
function Url(a){this.setUrl(a)}
Url.prototype.setUrl=function(a){
var undefined,d,c,b,h,e,i,f,g,j;
this.queryString={};
this.url=a;
if(typeof a!="undefined") {
this.host=this.file=this.path=undefined;
if((c=a.indexOf("?"))==-1) b=a;
else {
b=a.substr(0,c);
d=((e=a.indexOf("#"))==-1?a.substr(c+1):a.substr(c+1,e-c-1)+"&"+a.substr(e+1)).split("&");
for(c=0;c<d.length;c++){
i=d[c].indexOf("=");
if(i>-1){
f=d[c].substring(0,i);
g=d[c].substring(i+1);
this.queryString[f]=unescape(g.replace(/\+/g," "))
} } }
h=b.replace(/^(https?|ftp):\/\/[^\/]+/,function(s){j=s;return ""}).split("/");
this.file=h.pop();
this.host=j;
this.path="/"+(h.length>0?h.join("/"):"");
}
}
</script>




There are currently no comments for this snippet.