Two examples of URL parsing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.