Skip to content

Instantly share code, notes, and snippets.

@lbj96347
Last active August 29, 2015 14:20
Show Gist options
  • Save lbj96347/4ba5a1704dd17c104245 to your computer and use it in GitHub Desktop.
Save lbj96347/4ba5a1704dd17c104245 to your computer and use it in GitHub Desktop.
javascript-get-url-parameter
function getParameter( name, url ) {
if (!url) url = location.href
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( url );
return results == null ? null : results[1];
}
getParameter('q', 'hxxp://example.com/?q=abc');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment