Menu Close

Get URL Parameters using jQuery

by jquerybyexample.net

In today’s post, you will see small piece of code but really effective and useful. That is how to get URL Parameters using jQuery. Now days every server language provide direct method to get the URL parameters but this is not straight forward with jQuery.

To implement this, I have created a function which returns value of any parameters variable.

function GetURLParameter(sParam)
 {
     var sPageURL = window.location.search.substring(1);
     var sURLVariables = sPageURL.split('&');
     for(var i = 0; i < sURLVariables.length; i++)
     {
         var sParameterName = sURLVariables[i].split('=');
         if (sParameterName[0] == sParam) 
         {
             return sParameterName[1];
         }
     }
 }

And this is how you can use this function assuming the URL is,
“http://dummy.com/?technology=jquery&blog=jquerybyexample”.

var tech = GetURLParameter('technology');
var blog = GetURLParameter('blog');

So in above code variable “tech” will have “jquery” as value and “blog” variable’s will be “jquerybyexample“.

Posted in News, Web Development

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *