Thursday, July 25, 2013

HowTo Get Query String Parameters using Jscript Function

A simple function that give you ability to retrieve query string parameters client side using javascript.

function getQueryStringParameter( name )

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

So, in order to retrieve a parameter, just type:

var paramValue = getQueryStringParameter('parameterName');

No comments: