Created
June 12, 2010 01:02
-
-
Save loopj/435267 to your computer and use it in GitHub Desktop.
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
// Extract "GET" parameters from a JS include querystring | |
function getParams(script_name) { | |
// Find all script tags | |
var scripts = document.getElementsByTagName("script"); | |
// Look through them trying to find ourselves | |
for(var i=0; i<scripts.length; i++) { | |
if(scripts[i].src.indexOf("/" + script_name) > -1) { | |
// Get an array of key=value strings of params | |
var pa = scripts[i].src.split("?").pop().split("&"); | |
// Split each key=value into array, the construct js object | |
var p = {}; | |
for(var j=0; j<pa.length; j++) { | |
var kv = pa[j].split("="); | |
p[kv[0]] = kv[1]; | |
} | |
return p; | |
} | |
} | |
// No scripts match | |
return {}; | |
} | |
// Mini version :) | |
function getParams(a){var b=document.getElementsByTagName("script");for(var i=0;i<b.length;i++){if(b[i].src.indexOf("/"+a)>-1){var c=b[i].src.split("?").pop().split("&");var p={};for(var j=0;j<c.length;j++){var d=c[j].split("=");p[d[0]]=d[1]}return p}}return{}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment