Skip to content

Instantly share code, notes, and snippets.

@jonkemp
Last active September 25, 2015 06:17
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 jonkemp/876105 to your computer and use it in GitHub Desktop.
Save jonkemp/876105 to your computer and use it in GitHub Desktop.
A simple function for getting parameters from a query string.
function query( key ) {
if ( location.href.indexOf("?") !== -1 ) {
var q = location.search,
p = [],
i, val;
q = q.slice(1);
if ( q.indexOf("&") !== -1 ) {
q = q.split("&");
for ( i=0; i < q.length; i++ ) {
p.push( q[i].split("=") );
}
for ( i=0; i < q.length; i++ ) {
if ( p[i][0] === key ) {
val = p[i][1];
}
}
} else {
p.push( q.split("=") );
if ( p[0][0] === key ) {
val = p[0][1];
}
}
return val;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment