Skip to content

Instantly share code, notes, and snippets.

@dustinpoissant
Last active February 14, 2018 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinpoissant/bff22759c012057b2a834da0268ba62f to your computer and use it in GitHub Desktop.
Save dustinpoissant/bff22759c012057b2a834da0268ba62f to your computer and use it in GitHub Desktop.
JavaScript $_GET
var $_GET = (function(){
var params = {};
if(location.href.indexOf("?") > -1){
var string = location.href.split("?")[1];
if(string.indexOf("#") > -1){
string = string.split("#")[0];
}
var kvp = string.split("&");
for(var i=0; i<kvp.length; i++){
var k = kvp[i].split("=")[0];
if(k != ""){
var v = kvp[i].split("=")[1];
params[k] = v;
}
}
}
return params;
})();
var $_GET=function(){var i={};if(location.href.indexOf("?")>-1){var r=location.href.split("?")[1];r.indexOf("#")>-1&&(r=r.split("#")[0]);for(var t=r.split("&"),a=0;a<t.length;a++){var f=t[a].split("=")[0];if(""!=f){var l=t[a].split("=")[1];i[f]=l}}}return i}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment