Last active
August 29, 2015 14:27
-
-
Save jamenlyndon/1dee48cb67ed9981d091 to your computer and use it in GitHub Desktop.
Use GET vars with JS
This file contains hidden or 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
// 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