Home > JavaScript > Get Querystring Using Javascript

Get Querystring Using Javascript

Getting querystring by using a server side programming language is something very easy and straight forward most of the times, but how about getting querystring using javascript?

Below I will show you an easy function you can add it to your page to get the querystring needed from the url

<script type=”text/javascript”>
function getQuerystring(key, default_) {
if (default_ == null) default_ = “”;
key = key.replace(/[\[]/, “\\\[“).replace(/[\]]/, “\\\]”);
var regex = new RegExp(“[\\?&]” + key + “=([^&#]*)”);
var qs = regex.exec(window.location.href);
if (qs == null)
return default_;
return qs[1];
var merchant_value = getQuerystring(‘merchant’);

// to test if working


P.S. if you need to use this function to show/hide a control in your page add the script before the body tag (</body>) so that all the controls are loaded.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: