I’m using the following code http://friendlybit.com/js/lazy-loading-asyncronous-javascript/ to make async calls but now I want to send custom var to this script and cannot figure it out.
(function() {
function async_load(){
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'http://yourdomain.com/script.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}
if (window.attachEvent)
window.attachEvent('onload', async_load);
else
window.addEventListener('load', async_load, false);
})();
Now I want to have custom var that is sent to “script.js”. That’s all, a simple var to be sent to JS. I’ve even tried by using query strings but no results.
Help please.
Just assign it to the global scope (with
window.varname = valuefor example) and the script you load will be able to use it, since it runs on the same page.