Get QueryString values in JavaScript


We can make use of the following functions to get the value of querystring parameters through JavaScript

// helper function to get the query string
function Querystring() {

var querystring =,;

var args = querystring.split(‘&’);

for (var i = 0; i < args.length; i++) {

var pair = args[i].split(‘=’);

 temp = unescape(pair[0]).split(‘+’);

 name = temp.join(‘ ‘);
temp = unescape(pair[1]).split(‘+’);
value = temp.join(‘ ‘);
this[name] = value;
this.get = Querystring_get;


function Querystring_get(strKey, strDefault) {
var value = this[strKey];
if (value == null) {
value = strDefault;
return value;

Suppose our current page url is


To get the value for id we’ll do this

var qs = new Querystring();

var idValue=qs.get(“id”, “”);



Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

2 thoughts on “Get QueryString values in JavaScript”

Please share your thoughts

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.