JS Processing URL Parameters

Source: Internet
Author: User

Hey, it's another pen test. Blame me for being too lazy and not thinking much. Always use someone else's code to get the URL parameter value, others code is written in regular expressions, the code is as follows:

1 function Geturlparam (name) {2     return decodeuricomponent ((newnull; 3 }

parameter explanation:name refers to the parameter name to get, the string variable.

The regular expression explains:

New RegExp (' (? | &) ' + name + ' = ([^&;] +?) (&|#|;| $) ', ' IG ' means:
① creates a regular expression that matches a string that begins with a character, or & that contains =, and ends with a & or # or;
②ig means ignoring case and making a string global search.

The Exec method is to retrieve a match for a regular expression in a string, and a matching string returns an array (the No. 0 element is a string that matches the regular expression), and so on, the matching character of the regular expression string is stored separately, and a null value is returned if it does not exist.
This takes the first subexpression (that is: ([^&;] +?) The string that we want to match.
Exec method Learning: JavaScript exec () method
Location.serach is the URL, and the string behind it (contains?).

The written examination just saw this problem, the mind is remorse ah, regret to unexpectedly put the split function to forget!! Although this writing is very chicken, but still can solve the problem!

Use Split to write the chicken code:

1 functionGeturlparam (name) {2         vararr = decodeuricomponent (Location.search.split ('? ') [1]). Split (' & ');3         varrequest=[];4         vartemp=[];5          for(vari = 0;i<arr.length;i++){6temp = arr[i].split (' = '));7Request[temp[0]] = temp[1];8         }9         returnRequest[name] | |NULL;Ten}

Slow and time-consuming, the code does not explain. is to use split continuous cutting cutting ...

JS processing 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.