dynamic load javascript from javascript

H

howachen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top