Last active
August 29, 2015 14:04
-
-
Save pinalbhatt/fd1b2c4e02d003db45f6 to your computer and use it in GitHub Desktop.
Reading Query String with JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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