Essentially I have a site that needs dynamically loaded content - specifically locales. I need multi-lingual support for my site, so the general idea is that I have a query param like ?language=english and english would then get appended to the header so that it grabs the right data to be used in my web page. So like:
//script 1
//getLanguage() gets the specified query parameter, like 'english'
$('head').append('<script src=' + getLanguage() + '.js'></script>');
Then throughout script 1 I would do like:
$('#mainHeader').append(window.i18n['home'].mainHead());
And this is the english version of the script where the variables are defined:
//english.js
(function(A) {
A.i18n = {
home: {
mainHead: function(b) { return 'test123'; },
}
}
})(this);
This works when running on a local webserver. Running it as a file (which is what I need to do) I get this:
"XMLHttpRequest cannot load file://...english.js?_=1449747918242. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource." AND "Uncaught TypeError: Cannot read property 'home' of undefined"
I have attempted to use pure javascript, and this gives "Uncaught TypeError: Cannot read property 'home' of undefined":
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= getLanguage() + '.js';
head.appendChild(script);
Any suggestions on how to proceed? I have been trying various potential solutions for a day now and nothing seems to work.