Hi,
Following the discussion that can be found here:
http://groups.google.com/group/comp....9da813c8527282
I modified mine and was trying to launch an alert message inside the
dynamically added script [data.js].
My sample codes
=============== =============== =============== ===
[data.js]
var remoteValue = 'Blah blah';
alert('File loaded... ' + remoteValue);
function alertME()
{
alert('alertME in data.js');
}
[HTML]
<a href="#" onclick="addScr ipt('data.js'); ">START</a>
<script type="text/javascript">
var x = 'im blank';
alert(x);
function addButton()
{
var oButton = document.create Element('input' );
oButton.value = 'Add script element';
oButton.setAttr ibute("onclick" , "alertME(); ");
oButton.type = 'button';
document.body.a ppendChild(oBut ton);
}
function getValues(x)
{
alert(x); // Shows 'removeValue'
setTimeout('ale rt('+x+')',0); // Shows 'Blah blah'
}
function addScript(uri)
{
var oScript = document.create Element('script ');
oScript.src = uri;
//var head = document.getEle mentsByTagName( 'head')[0];
//head.appendChil d(oScript);
document.body.a ppendChild(oScr ipt); //-head or body, both works
in Firefox 2.0.0.4
addButton();
}
</script>
The alert messages for 'x' appeared correctly. But Firebug return this
error: alertME is not defined, and 'alertME in data.js' never appear.
Is this a limitation in Javascript? Or Did I miss out on something
important?
Your suggestion are trully appreciated.
Thanks.