Skip to content

Instantly share code, notes, and snippets.

@rococodogs
Created July 24, 2014 19:31
Show Gist options
  • Save rococodogs/020f4fe7efc7e6e8416b to your computer and use it in GitHub Desktop.
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)
// 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