Return to Snippet

Revision: 9625
at November 14, 2008 16:36 by charmcitycoder


Initial Code
function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

Initial URL
http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx

Initial Description
Many thanks to bloggingdeveloper.com for this one. Works like a charm. Usage is similar to server side built-in functions.

Initial Title
Function - Get querystring variable

Initial Tags
javascript

Initial Language
JavaScript