Javascript Query String Parse

by Jim Jan 30, 2007 2:38 PM

This shouldn't be so hard to google. To parse an html page's query string with Javascript, using a regular expression:

// Get the value of one of the arguments in the query string
function getFieldValue(name)
{
    var match = (new RegExp('[?&;]' + name + '=([^&;#]*)')).exec(location.search);
    return match ? unescape(match[1]) : "";
}

Returns an empty string if the name doesn't match.

Tags: ,

Add comment


(Shows Gravatar icon; will not be displayed)

  Country flag
Click to change captcha
biuquote
  • Comment
  • Preview
Loading