Created
July 24, 2014 19:31
-
-
Save rococodogs/020f4fe7efc7e6e8416b to your computer and use it in GitHub Desktop.
generate object from querystring via src (stolen from http://feather.elektrum.org/book/src.html)
This file contains 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
// get qs from src path | |
// http://feather.elektrum.org/book/src.html | |
var scripts = document.getElementsByTagName('script'); | |
var thisIdx = scripts.length - 1; | |
var thisScript = scripts[thisIdx]; | |
var qs = {}; | |
var str = thisScript.src | |
.replace(/^[^\?]+\??/, '') // strip out address | |
.split(/\&/) // split on ampersands | |
.map(function(it){ // parse thru each key=val, split on equal sign and assign to qs object | |
var s = it.split(/\=/); | |
qs[s[0]] = decodeURIComponent(s[1]); | |
}); | |
// qs is now the object to use: | |
// { | |
// abc: "123", | |
// xyz: "789" | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment