Created
January 27, 2010 10:13
-
-
Save vrutberg/287707 to your computer and use it in GitHub Desktop.
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
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