Skip to content

Retrieving Query String Values on JS

October 31, 2012

If for whatever reason you need to do JS scripting on the client side for obtaining any Query String you may place on your browser window.
You many think that you need to do fancy JQuery in order to process it, wrong, you don’t need to, as there is plain Javascript that can handle its values.Here is a very useful function in Javascript for retrieving Query String Values on the client side (without using JQuery).

 

function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}
Advertisements

From → Uncategorized

Leave a Comment

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: