Skip to content

Instantly share code, notes, and snippets.

@jamenlyndon
Last active August 29, 2015 14:27
Show Gist options
  • Save jamenlyndon/1dee48cb67ed9981d091 to your computer and use it in GitHub Desktop.
Save jamenlyndon/1dee48cb67ed9981d091 to your computer and use it in GitHub Desktop.
Use GET vars with JS
// Read the GET variables
var $_GET = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
function decode(s) {
return decodeURIComponent(s.split("+").join(" "));
}
$_GET[decode(arguments[1])] = decode(arguments[2]);
});
// Use the GET variables
if (typeof $_GET['something'] !== 'undefined') {
// Do something with $_GET['something']
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment