Get URL parameters

Source: Internet
Author: User

Title Description

Get the parameters in the URL
1. Specify the parameter name, return the value of the parameter, or empty string
2. Do not specify the parameter name, return all parameter object or {}
3. If there are multiple parameters with the same name, the array is returned

1 functionGeturlparam (sURL, SKey) {2 varparam = Surl.split (' # ') [0].split ('? ') [1];3if(SKey) {//Specifying parameter names4varSTRs = Param.split (' & '));5varArrs =NewArray ();//returns an array if more than one parameter with the same name is present6 for(vari = 0, len = strs.length; i < Len; i++){7varTMP = strs[i].split (' = '));8if(Tmp[0] = =SKey) {9Arrs.push (tmp[1]);Ten             } One         } Aif(Arrs.length = = 1) {//returns the value of this parameter or an empty string - returnArrs[0]; -}Else if(Arrs.length = = 0){ thereturn""; -}Else { - returnArrs; -         } +}Else{//does not specify a parameter name, returns all parameter objects, or {} -if(param = = Undefined | | param = = ""){ + return {}; A}Else { atvarSTRs = Param.split (' & ')); -varArrobj =NewObject (); - for(vari = 0, len = strs.length; i < Len; i++){ -varTMP = strs[i].split (' = ')); -if(! (Tmp[0]incharrobj)) { -Arrobj[tmp[0]] = []; in                 } -Arrobj[tmp[0]].push (tmp[1]);  to             } +returnarrobj; -         } the     } *}

Links: Https://www.nowcoder.com/questionTerminal/a3ded747e3884a3c86d09d88d1652e10
Source: Niu Ke Net

Get URL parameters

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.