Javascript Check if Query String Parameter Exists in current URL

This Javascript function checks if the parameter supplied exists in the query string.  If the parameter supplied is found in the query string of the current URL, the function will return true.  If the parameter is not found, false is returned.

See also: getParameter() - This function returns the value of the parameter if found, and false if it is not found which can be used instead of the checkParameterExists() function below



function checkParemeterExists(parameter)
{
   //Get Query String from url
   fullQString = window.location.search.substring(1);
   
   paramCount = 0;
   queryStringComplete = "?";

   if(fullQString.length > 0)
   {
       //Split Query String into separate parameters
       paramArray = fullQString.split("&");
       
       //Loop through params, check if parameter exists.  
       for (i=0;i<paramArray.length;i++)
       {
         currentParameter = paramArray[i].split("=");
         if(currentParameter[0] == parameter) //Parameter already exists in current url
         {
            return true;
         }
       }
   }
   
   return false;
}


Next: Javascript Remove a parameter from the query string if found in current url

Previous: Javascript Add Query String Parameter

Javascript Query String Manipulation (TOC)

Comments

Post a Comment

Popular posts from this blog

Php RSS2Writer (v2.1) - Generate RSS 2.0 Feed - Usage Instructions & Download

VBScript String Clean Functions -3 Methods to Remove or Replace Characters in a String

DIY SharePoint Marketing Tips & Tools - Do Follow SharePoint Article Libraries