Skip to content

Instantly share code, notes, and snippets.

@lxneng
Created June 10, 2011 02:46
Show Gist options
  • Save lxneng/1018155 to your computer and use it in GitHub Desktop.
Save lxneng/1018155 to your computer and use it in GitHub Desktop.
Get query string values in JavaScript
// Revised, cooler.
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)')
.exec(window.location.search);
return match ?
decodeURIComponent(match[1].replace(/\+/g, ' '))
: null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment