View Full Version : Help! Trying to figure out dynamic javascript loading (after hours of research!)

07-17-2007, 08:01 PM
Hello there,

I'm trying to find a practical example of something that uses this pattern, which dynamically loads javascript into a page that has already been loaded:

I have found numerous examples of this, however what I'm really looking for is an example that shows how to dynamically load a javascript file with functions, and then check to see if the page or function is loaded, and then execute the function. If you just execute the function after loading the javascript, it won't be fully loaded yet and the function won't fire.

I've been searching through the web for several hours trying to find a solution, but have not found a good one yet. Any help would be much appreciated!!!

Thank you,

07-17-2007, 09:30 PM
There are two ways:

1. If you are loading the script as plain text using XMLHTTPRequest and doing eval(), then all the functions within the loaded script are available after eval function.

2. If you are dynamically appending <script> node, add a call to load notification function that resides in the page to the script you are loading:

// Main page
function loadNotify(file)
{ alert('File ' + file + 'loaded');

// Dynamically loaded JS:

/* all
code */