Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2007
    Thanked 0 Times in 0 Posts

    Help! Trying to figure out dynamic javascript loading (after hours of research!)

    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,

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Nashua, NH
    Thanked 0 Times in 0 Posts
    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 */
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts