I am trying to get some variables into a script I am loading. Currently, I have like
window.myApp = {
id: ''
};
And I am loading the javascript like
(function() {
var s = document.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'http://blah.com/widget.js';
var x = document.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
})();
widget.js has the namespace window.myApp and I am trying to get the .id into it ? How can I do that?
Within widget.js you could do this:
That is, store a reference to the existing
window.myAppobject, then setwindow.myAppto another object, then copy the properties across. You could add aniftest to handle the case where the same property is defined in both JS files.