Home Search Member List Faq Register Login  
JavaScript Tips
Retrieve query string values

Thread Starter: Karamasoft   Started: 09-18-2007 12:44 PM   Replies: 0
 Karamasoft Support Forums » General Discussions » JavaScript Tips » Retrieve query string values
 Printable Version    « Previous Thread   Next Thread »
  18 Sep 2007, 12:44 PM
Karamasoft is not online. Last active: 11/10/2017 3:24:14 PM Karamasoft

Top 10 Posts
Joined on 09-05-2004
Posts 6,818
Retrieve query string values

ASP.NET provides Request.QueryString collection that retrieves the values of the variables in the HTTP query string, but there is no built-in mechanism to retrieve query string collection on the client-side. However, you can parse the window location search property to get the query string values by using the GetAttributeValue method that we provided in one of our previous tips to center your window. Note that window.location.search property gets or sets the substring of the href property that follows the question mark.

function GetAttributeValue(attribList, attribName, firstDelim,

secondDelim) {

var attribNameLowerCase = attribName.toLowerCase();

if (attribList) {

var attribArr = attribList.split(firstDelim);

for (var i = 0, loopCnt = attribArr.length; i < loopCnt; i++) {

var nameValueArr = attribArr[ i ].split(secondDelim);

for (var j = 0, loopCnt2 = nameValueArr.length; j < loopCnt2;

j++) {

if (nameValueArr[0].toLowerCase().replace(/\s/g, '') ==

attribNameLowerCase && loopCnt2 > 1) {

return nameValueArr[1];






This method takes three arguments: a name/value pair list, the attribute name to retrieve its value, the first delimiter and the second delimiter. The first delimiter will be ampersand and the second delimiter would be equal sign to parse query string variables.

Then you can use the following method to retrieve the query string value for given query string variable name.

function GetQueryStringValue(varName) {

return GetAttributeValue(window.location.search.substring(1), varName, '&', '=');


 Page 1 of 1 (1 items)
Karamasoft Support Forums » General Discussions » JavaScript Tips » Retrieve query string values

You can add attachments
You can post new topics
You can reply to topics
You can delete your posts
You can edit your posts
You can create polls
You can vote in polls
Forum statistics are enabled
Forum is unmoderated

© 2002-2018 Karamasoft LLC. All rights reserved.