Skip to content

Instantly share code, notes, and snippets.

@zachpendleton
Created September 15, 2011 17:06
Show Gist options
  • Save zachpendleton/1219832 to your computer and use it in GitHub Desktop.
Save zachpendleton/1219832 to your computer and use it in GitHub Desktop.
get param from URL (rails friendly)
function getParam(name){
var pathRegex = new RegExp(name + '\/([^\/]+)'),
searchRegex = new RegExp(name + '=([^&]+)'),
match;
match = (window.location.pathname.match(pathRegex) || window.location.search.match(searchRegex));
if (!match) return false;
return match[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment