f



dynamic load javascript from javascript

hi,

from here:
http://www.activewidgets.com/javascript.forum.6114.15/dynamic-load-javascript-from-javascript.html

there is a method to load js from js, e.g.

//---------------------------------------------------------------------------------------
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'snip.js';
document.getElementsByTagName('head')[0].appendChild(script);
//---------------------------------------------------------------------------------------

this method works great, but there is a bug(?) when using with IE, the
script can't execute immediately after it is loaded, i.e.

(from the link above)
---------------------------------------------------------------------------------------------------------------------------------------
If you do as you say, and you load a JS file dynamically as mentioned
above, any functions in that file should be available from that point
forward. There is a bug in IE that you need to be aware of. You need to
end the script you are in before calling any functions in the newly
loaded script. This is what I mean:


<script>
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'snip.js';
document.getElementsByTagName('head')[0].appendChild(script);
</script>
<script>
getSomething();
</script>
----------------------------------------------------------------------------------------------------------------------------------------


i re-post this problem here is to look for a workaround for this issue,
let's share about it :)


regards,
howa

0
howachen (521)
2/8/2006 4:01:06 PM
comp.lang.javascript 38370 articles. 0 followers. javascript4 (1315) is leader. Post Follow

0 Replies
1369 Views

Similar Articles

[PageSpeed] 35

Reply: