Get Query String Values by Javascript
Script Function
function GET() {
var data = [];
for(x = 0; x < arguments.length; ++x)
data.push(location.href.match(new RegExp("/\?".concat(arguments[x],"=","([^\n&]*)")))[1])
return data;
}
Example:
data = GET("id","name","foo");
query string : ?id=3&name=jet&foo=b
returns:
data[0] // 13
data[1] // jet
data[2] // b
or
alert(GET("id")[0]) // return 3
Comments
Post a Comment