Return to Snippet

Revision: 12542
at March 18, 2009 14:46 by nelsnelson


Initial Code
function gup( 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];
}

Initial URL
http://www.netlobo.com/url_query_string_javascript.html

Initial Description
Here is a small function [[lobo235](http://www.netlobo.com/javascript_tooltips.html "Javascript Tool-tips")] wrote that will parse the window.location.href value and return the value for the parameter you specify. It does this using javascript's built in regular expressions.

Initial Title
Javascript function to get URL query string parameters

Initial Tags
url, javascript

Initial Language
JavaScript