How to get the value from the GET parameters with jquery.
Friday, February 03, 2017
Example url http://example.com?id=123&name=mahedi
To get the value of id and name with jquery.
Function code:
function getUrlParameters(parameter, staticURL, decode){
var currLocation = (staticURL.length)? staticURL : window.location.search,
parArr = currLocation.split("?")[1].split("&"),
returnBool = true;
for(var i = 0; i < parArr.length; i++){
parr = parArr[i].split("=");
if(parr[0] == parameter){
return (decode) ? decodeURIComponent(parr[1]) : parr[1];
returnBool = true;
}else{
returnBool = false;
}
}
if(!returnBool) return false;
}
//uses
var id = getUrlParameters("id", "", true);
var name= getUrlParameters("name", "", true);
Labels: JS
Post a Comment