Query String Arguments
The following function parses the query string and returns an object with entries for each argument:
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
<script>
function getQueryStringArgs(queryString, paraName){
var qs = queryString;
var args = {};
var items = qs.split("&");
for (var i=0; i < items.length; i++){
var item = items[i].split("=");
var name = decodeURIComponent(item[0]);
var value = decodeURIComponent(item[1]);
if (name.length) {
args[name] = value;
}
}
return args;
}
document.writeln(getQueryStringArgs("q=javascript&num=10")["q"]); //"javascript"
document.writeln(getQueryStringArgs("q=javascript&num=10")["num"]); //"10"
</script>
</body>
</html>