I have one complicated situation with JavaScript. I have created object. This object loads JS, CSS files dinamicly( see load function ). My problem is that I want to add onload event when object file is loaded and change some values in that object.
My object constructor:
function lib( type, url )
{
//Varaibles
this.URL = url; //Files url
this.TYPE = type; //Files type( can by CSS or JS )
this.READY = false; //Files loaded status
//Functions
this.load = load; //Method, which is called to start loading file
this.status = status; //Return READY status( false or true )
}
So I'm trying on file load change READY status. This thing I want to set in load function. For now I have this load function:
function load()
{
var object = this;
switch ( this.TYPE.toUpperCase() )
{
case "JS" :
{
var script = document.createElement( "script" );
script.setAttribute( "type", "text/javascript" );
script.setAttribute( "src", this.URL );
document.getElementsByTagName( "head" )[0].appendChild( script );
if( navigator.appName == "Microsoft Internet Explorer" )
{
script.onreadystatechange = function () { this.READY = true; };
} else {
script.onload =function () { this.READY = true; };
}
break;
}
( Here should be CSS loading... )
}
}
So guys, I need to see my code and see what I do wrong