Skip to content

Instantly share code, notes, and snippets.

@abhiomkar
Created July 16, 2013 07:12
Show Gist options
  • Save abhiomkar/6006469 to your computer and use it in GitHub Desktop.
Save abhiomkar/6006469 to your computer and use it in GitHub Desktop.
read query parameter values from current URL in JavaScript
window.location.param = function(key) {
var value;
window.location.search.slice(1).split('&').map(function(e) {
e = decodeURIComponent(e);
if (e.indexOf(key + '=') === 0) {
value = e.slice(key.length + 1);
return false;
}
});
return value;
};
// ?id=123&ws=abc&ls=xyz
window.location.param('id'); // '123'
window.location.param('ls'); // 'xyz'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment