Programatically downloading javascript files and executing methods from it...

R

Raj

Hello all,

I have a situation where I would like to have one small javascript
embedded in my html files. On page load, this javascript gets executed.
At this point, based on the content of the html, it decides which other
[much larger] java script files are needed. It should then
progrmatically download the new scripts and execute certain methods
[with predefined method signatures] from the newly downloaded sources.

Can this be done?!

Any tips in this regard are much appreciated.

Thanks in advance.
Raj
 
M

Martin Honnen

Raj said:
I have a situation where I would like to have one small javascript
embedded in my html files. On page load, this javascript gets executed.
At this point, based on the content of the html, it decides which other
[much larger] java script files are needed. It should then
progrmatically download the new scripts and execute certain methods
[with predefined method signatures] from the newly downloaded sources.

With the W3C DOM you can dynamically create any element and insert it
into the document so you can create and insert a new script element e.g.
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'file.js';
document.body.appendChild(script);
But browsers had problems implementing that feature so it does not work
in older Mozilla versions or in early Opera 7 versions.
And even more important, the browser loads the script asynchronously so
you cannot call a method in the script file without setting up load
handlers.
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top