Created
July 16, 2013 07:12
-
-
Save abhiomkar/6006469 to your computer and use it in GitHub Desktop.
read query parameter values from current URL in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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