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