Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Created June 22, 2016 21:45
Show Gist options
  • Select an option

  • Save leepettijohn/3f50b8c78456fb0da9fc8836e8ca9e9a to your computer and use it in GitHub Desktop.

Select an option

Save leepettijohn/3f50b8c78456fb0da9fc8836e8ca9e9a to your computer and use it in GitHub Desktop.
jQuery - Get 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]);
});
//This will either alert the "id" variable in the URL or return 'undefined'
alert($_GET['id']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment