Skip to content

Instantly share code, notes, and snippets.

@skipjac
Created October 1, 2013 16:35
Show Gist options
  • Save skipjac/6781340 to your computer and use it in GitHub Desktop.
Save skipjac/6781340 to your computer and use it in GitHub Desktop.
get url parameters with javascript
function getParameterByName( name,href )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( href );
if( results == null )
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
getParameterByName('loan', window.location)
"1234"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment