Skip to content

Instantly share code, notes, and snippets.

@netsuite
Created April 19, 2013 16:02
Show Gist options
  • Save netsuite/5421318 to your computer and use it in GitHub Desktop.
Save netsuite/5421318 to your computer and use it in GitHub Desktop.
js: Parse Query String
/**
* Parse Query String
* @param {string} name of value
* @return {string}
* @uses : var year = parseQueryString("year"); // returns "2013"
*/
function parseQueryString ( 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];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment