I've been using the following dynamic scripting technique for executing a site-specific subroutine in an otherwise generic script, viz
siteExtras : function (cid, extras) {
var script = document.createElement("script");
script.src = 'https://' + cid + '.mysite.com/' + cid + "_extras.js?" + extras;
script.type = 'text/javascript';
var h = document.getElementsByTagName("script")[0];
h.parentNode.insertBefore(script, h);
},
So given the following invocation
this.siteExtras('cycles','concept=tandem');
script.src thus becomes
https://cycles.mysite.com/cycles_extras.js?concept=tandem
where cycles is a client-specific subdomain I've created on mysite.com.
The issue I'm having is that I've been assuming that cycles_extras.js would be capable of reading it's own search string, using
//cycles_extras.js
function getParameterByName(name) {
var args = location.search.substr(1).split('&');
for (var i = 0; i < args.length; i++) {
var parts = args[i].split('=');
if (name === parts[0]) {
return unescape(parts[1]);
}
}
return "";
}
var concept = getParameterByName('concept');
...
however, when cycles_extras.js is executed, it takes its location.search from the browser, not from the https://cycles.mysite.com/cycles_extras.js?concept=tandem URL.
Am I attempting the impossible here? Or is something missing?