Skip to content

Instantly share code, notes, and snippets.

@pinalbhatt
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinalbhatt/fd1b2c4e02d003db45f6 to your computer and use it in GitHub Desktop.
Save pinalbhatt/fd1b2c4e02d003db45f6 to your computer and use it in GitHub Desktop.
Reading Query String with JavaScript
/*
Javascript function to read QueryString parameters.
More details bloged at http://blog.pbdesk.com/2008/11/reading-query-string-with-javascript.html
JSFiddle: http://jsfiddle.net/PinalBhatt/sBkur/
*/
function GetQueryStringValue(parameterName) {
var objQRs = new Object();
window.location.search.replace(new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { objQRs[$1] = $3; });
return objQRs[parameterName]
}
/*
So if you have a url like page.html?id=1000&code=zoox&dt=10/31/2009 you can use following code to retrieve the values of querystring parameters id, code and dt.
*/
var id= GetQueryStringValue("id");
var code = GetQueryStringValue("code");
var dateValue = GetQueryStringValue("dt");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment