Javascript can load a script dynamically?

C

Chamnap

Javascript has no ways to load a script dynamically when the page is
already loaded?

Thanks
Chamnap
 
C

Chamnap

After calling this function, can I immediately call a function within
that script?

Thanks
Chamnap
 
C

Chamnap

One more thing, what is about adding this code to the head section to
load a google map key?

<script src="http://maps.google.com/maps?
file=api&amp;v=2&amp;key=#{GOOGLE_MAPS_KEY}" type="text/javascript"></
script>
<!--[if IE]><style type="text/css"> v\:*
{ behavior:url(#default#VML); } </style><![endif]-->

Any idea?
Thanks
Chamnap
 
C

Chamnap

Thanks for your reply.
Ok, All in all. I want to ask you one question relating to the load
the external script dynamically using javascript. Then, you show how
to load the external script. I want to know when can I use functions
that are in the external script. Can I use it immediately after using
your code? Is it reliable?

function loadJSFile(fileURL){
var newScript = document.createElement('script');
newScript.type = "text/javascript";
newScript.src = fileURL;
document.getElementsByTagName('head')[0].appendChild(newScript);

}

loadJSFile('someFile.js');
someFunctionInSomeFile();

Should I use setInterval to check whether it is load successfully or
not? Or should I use setInterval to run a test of one function from
that external script? Or....

Thanks
Chamnap
 
T

Thomas 'PointedEars' Lahn

DS said:
After calling this function, can I immediately call a function within
that script?
[...]

Not immediately for all browsers.
From memory, Firefox needs a delay of about 10ms, after the script has
finished loading, to be able to *reliably* call any function.

How did you get that idea?


PointedEars
 

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

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top