Hi,
That function looks for the parameter "name" in the curent page address.
The code inside function filters the "name" and returns the result if it is find in the page URL, or empty data.
MarPlo
Junior Poster in Training
55 posts since Apr 2012
Reputation Points: 1
Solved Threads: 15
Skill Endorsements: 0
1.function gID(name) {
2. name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
3. var regexS = "[\\?&]"+name+"=([^&#]*)";
4. var regex = new RegExp( regexS );
5. var results = regex.exec( window.location.search );
6. if( results == null )
7. return "";
8. else
9. return results[1];
}
Line 1, declare function prototype (name & arguments)
Line 2, escape characters '[' and ']' by adding a backslash in front of them (need this for regular expression)
Line 3, create a regular expression string that start with either a question mark '?' or ampersand '&', follows by the incoming argument, and ends with an equal sign and any of at composition characters '^', '&', and '#' or none.
Line 4, create a regular expression object
Line 5, attempt to match the regular expression with the current window's argument call (for GET method, i.e. http://www.domainname.com/page.html?v=1,p=2 which results in "?v=1,p=2" for window.location.search)
Line 6, check if it could match
Line 7, return an empty string if not found the match
Line 8, else
Line 9, return the matched if found. The match is after will be any pattern inside the parenthesis in the regular expression (any char sequence right after & or # including '&' or '#').
I'm not sure if the regular expression is what you need though...
Taywin
Posting Maven
2,633 posts since Apr 2010
Reputation Points: 275
Solved Threads: 376
Skill Endorsements: 17