Skip to content

Instantly share code, notes, and snippets.

@pawiromitchel
Created January 27, 2017 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawiromitchel/306005cb2c8b6d177c0c2ace5f862590 to your computer and use it in GitHub Desktop.
Save pawiromitchel/306005cb2c8b6d177c0c2ace5f862590 to your computer and use it in GitHub Desktop.
JS - get the parameter from the URI
function getUriParam(name){
if(name=(new RegExp('[?&]'+encodeURIComponent(name)+'=([^&]*)')).exec(location.search))
return decodeURIComponent(name[1]);
}
// usage -> url: http://localhost/index.html?id=1
var a = getUriParam('id');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment