Javascript Query String

The query string is reachable through window.location.search property. Splitting it by & gives you list of passed GET parameters.


function GetPageParameter(param) {
var query ='';
if (window.location.search.length>3){
//removes '?' from the query string
query = window.location.search.substring(1);
}else{
return '';
}
params = query.split("&");
for (i=0;i1){
if (pair[0] == param) {
return pair[1];
}
}else{
return '';
}
}
return '';
}

var value = GetPageParameter("value");

No comments:

Post a Comment