Get query string parameter using JavaScript
Following code will help in fetching the value of a query string parameter.
function GetQueryStringParameter(parameter) { var search = location.search.substring(1); var queryStringParameters = JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}') return queryStringParameters[parameter]; }
Usage:
If URL is http://server/page.html?id=1
Then usage would be GetQueryStringParameters(“id”) which would return 1