Właśnie napisałem coś podobnego.
function Autoload() {}
Autoload.aFiles = new Array('options', 'background')
Autoload.init = function()
{
$Head = document.getElementsByTagName("head")[0];
for($index in Autoload.aFiles)
{
$Src = document.createAttribute("src");
$Src.nodeValue = "text/javascript"
$Type = document.createAttribute("type");
$Type.nodeValue = "/script/"+Autoload.aFiles[$index]+".js"
$Script = document.createElement('script');
$Script.setAttributeNode($Src);
$Script.setAttributeNode($Type);
$Head.appendChild($Script);
}
alert($Head.innerHTML)
Background.init();
}
window.onload = Autoload.init();
I teraz innerHTML jest poprawny, ale! Niestety dalej wyświetla komunikat: Uncaught ReferenceError: Background is not defined
edit>
OMG ! Chyba sobie kawki zaparzę bo takie debilne błędy popełniam że aż mnie to smuci...
edit>>
function Autoload() {}
Autoload.aFiles = new Array('options', 'background')
Autoload.init = function()
{
$Head = document.getElementsByTagName("head")[0];
for($index in Autoload.aFiles)
{
$Src = document.createAttribute("src");
$Src.nodeValue = "script/"+Autoload.aFiles[$index]+".js";
$Type = document.createAttribute("type");
$Type.nodeValue = "text/javascript";
$Script = document.createElement('script');
$Script.setAttributeNode($Src);
$Script.setAttributeNode($Type);
$Head.appendChild($Script);
}
Background.init();
}
window.onload = Autoload.init();
Poprawiłem. Wszystko jest tam gdzie trzeba. A on dalej nie mi wrzeszczy że nie ma klasy.
function Autoload() {}
Autoload.aFiles = new Array('options', 'background')
Autoload.include = function($sFile)
{
if (document.createElement && document.getElementsByTagName)
{
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', $sFile);
head.appendChild(script);
} else {
alert('Twoja przeglądarka to stara dupa nie potrafi obsługiwać DOM. Zmień ją!');
}
}
Autoload.init = function()
{
for($index in Autoload.aFiles)
{
Autoload.include("script/"+Autoload.aFiles[$index]+".js");
}
Background.init();
}
Tak też nie działa. Mimo że w inspektorze kodu widzę że dodał obie linijki.