Skip to content

Instantly share code, notes, and snippets.

@sunliwen
Created September 22, 2013 12:27
Show Gist options
  • Save sunliwen/6659445 to your computer and use it in GitHub Desktop.
Save sunliwen/6659445 to your computer and use it in GitHub Desktop.
Found this useful snippet in http://getbootstrap.com/customize/
function getQueryParam(key) {
key = key.replace(/[*+?^$.\[\]{}()|\\\/]/g, "\\$&"); // escape RegEx meta chars
var match = location.search.match(new RegExp("[?&]"+key+"=([^&]+)(&|$)"));
return match && decodeURIComponent(match[1].replace(/\+/g, " "));
}
// ?id=123
// getQueryParam('id') --> 123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment