jeet_sen wrote:
I cannot perform any action from within the loaded script. After
loading the script dynamically I planned to source in the object
literal data.
You can do that but you have to wait until the script has been loaded
and executed. IE supports the onreadystatechange event handler, Mozilla
a load event listener
function loadScript (url, callback) {
var scriptElement = document.createElement('script');
scriptElement.type = 'text/javascript';
scriptElement.src = url;
if (typeof scriptElement.addEventListener != 'undefined') {
scriptElement.addEventListener(
'load',
function (evt) { callback(); },
false
);
}
else if (typeof scriptElement.attachEvent != 'undefined') {
scriptElement.attachEvent(
'onreadystatechange',
function () {
if (scriptElement.readyState == 'complete') {
callback();
}
}
);
}
document.getElementsByTagName('head')[0].appendChild(scriptElement);
}
loadScript(
'file.js',
function () { alert(GOD.name); }
);
Opera 8 however does not support those event handlers/listeners on the
script element, hopefully Opera 9 will do.
--
Martin Honnen
http://JavaScript.FAQTs.com/