Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created October 23, 2015 10:55
Show Gist options
  • Save andreasvirkus/7e932c40ab72d42fdf91 to your computer and use it in GitHub Desktop.
Save andreasvirkus/7e932c40ab72d42fdf91 to your computer and use it in GitHub Desktop.
/**
* Two snippets to query the GET variable from the URL
*
* @param variable
* @returns {*} value of the GET variable or false when it's missing
*/
function queryGetVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
function queryGetVariable(variable) {
var value = location.search.match(new RegExp("[\?\&]" + variable + "=([^\&]*)(\&?)","i"));
return value ? value[1] : false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment