How to get parameter values from href in jquery


 
For get a specific parameter value of url. you have to set below Javascript code

   var url = window.location.href;
   var queryStringIdx = url.indexOf('?');
   var pairs = url.substr(queryStringIdx + 1)
         .split('&')
         .map(function(p) { return p.split('='); });
   var result = { };
   for (var i = 0; i < pairs.length; i++) {
      result[decodeURIComponent(pairs[i][0])] = decodeURIComponent(pairs[i][1]);
   }

If your URL is “http://EXAMPLE.COM/index.php?id=8&uid=3&#8221;

and you want to get the value of uid then you have to use below code

   var uid = result['uid'];
   alert(uid);

Output :

3

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

Advertisements

One thought on “How to get parameter values from href in jquery

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