Skip to content

Instantly share code, notes, and snippets.

@vrutberg
Created January 27, 2010 10:13
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 vrutberg/287707 to your computer and use it in GitHub Desktop.
Save vrutberg/287707 to your computer and use it in GitHub Desktop.
function queryParam(key) {
// if it doesn't contain a question mark, return undefined
var qmPos = window.location.href.indexOf("?");
if(qmPos === -1) {
return undefined;
}
// if it doesn't contain our key, also return undefined
var keyPos = window.location.href.indexOf(key+"=", qmPos);
if(keyPos === -1) {
return undefined;
}
var ampPos = window.location.href.indexOf("&", keyPos);
return window.location.href.substring(keyPos+(key+"=").length, ampPos === -1 ? window.location.href.length : ampPos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment