A useful function was found today in the Rhino book Urlargs (extracts the parameters in the search string for the URL). We often see some page link address followed by parameters, such as http://www.xxx.com/?username=yyy&password=zzz and so on, many times we need to get the values of these parameters (YYY and ZZZ), You can then take advantage of the Urlargs function, which is obtained by the property of the return value of the function (the return value is an object).
Urlargs Function Code:
Copy Code code as follows:
function Urlargs () {
var args = {};
var query = location.search.substring (1);
var pairs = query.split (' & ');
for (var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexof (' = ');
if (pos = = 1) continue;
var name = pairs[i].substring (0,pos);
var value = pairs[i].substring (pos + 1);
Value = decodeuricomponent (value);
Args[name] = value;
}
return args;
}
How to use:
Copy Code code as follows:
var args = Urlargs ();
var username = Args.username; yyy
var password = Args.password; zzz