Skip to content

Instantly share code, notes, and snippets.

@niisar
Created March 18, 2015 11:24
Show Gist options
  • Save niisar/70637ada19ea12d7276e to your computer and use it in GitHub Desktop.
Save niisar/70637ada19ea12d7276e to your computer and use it in GitHub Desktop.
Read query string in js
//read query string in js
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment