Example one:
/*resolves the name=value parameter in the URL lookup string to store the Name=value pair in the object property, and returns the object alert (Getquery (). Name)*/functionGetquery () {varobj={};//define an empty object varArr=location.search.substring (1). Split (' & ');//Get Lookup Parameters for(vari=0;i<arr.length;i++) { if(Arr[i].indexof (' = ') ==-1)//If you can't find it, skip it. Continue; Else{Arr[i]=arr[i].split (' = ')); obj[arr[i][0]]=ARR[I][1];//Store As object property } } returnObj//returns the parsed argument}
Example two:
/*parses a URL and generates a Window.location object containing the domain href: ' contains the full URL ', Origin: ' contains the protocol to pathname before the content ', protocol: ' URL used by the protocol, containing the end of: ', Host: ' Full hostname, including: ' and ' Port ', hostname: ' hostname, not port ', ' Port ', pathname: ' Path/start of resource access on server ', Search: ' Query string, '? Start ', HASHS: ' #开头的fragment identifier ' @param {string} URL to parse Url@return{object} object containing URL information*/functionparseurl (URL) {varresult={}; varkeys=[' href ', ' origin ', ' protocol ', ' host ', ' hostname ', ' port ', ' pathname ', ' search ', ' hashs ']; varI,len; varreg=/([^:]+:) \/\/(([^:\/\?#]+) (: \d+)?)] (\/[^?#]*)? (\? [^#]*)? (#.*)?/; varmatchs=reg.exec (URL); if(matchs) { for(i=keys.length-1;i>=0;i--) {Result[keys[i]]=matchs[i]?matchs[i]: "; } } returnresult;}
Two examples of URL parsing