Link to home
Start Free TrialLog in
Avatar of cali_oo7
cali_oo7

asked on

javascript concurrency issue

i am having a problem with javascript continuing to process before a function is completed.
what i am trying to do is call the following function to include a .js file so that its functions will be available to my program.

function include_dom(script_filename) {
    var html_doc = document.getElementsByTagName('head').item(0);
    var js = document.createElement('script');
    js.setAttribute('language', 'javascript');
    js.setAttribute('type', 'text/javascript');
    js.setAttribute('src', script_filename);
    html_doc.appendChild(js);
    return false;
}

after i call the include_dom function to access a .js file, i immediately start trying to use the .js file's functions. the problem i am having is that the browser is continuing to process the code before the .js file has been included and is running into problems trying to call a function that has not been loaded in the .js file yet.

I need a  way to tell the browser to stop executing code until the include_dom function returns and the .js file has been added.

An example of my code is as follows:

include_dom('some_script.js');
some_scripts_function();
Avatar of third
third
Flag of Philippines image

try to set a delay, like,

include_dom('some_script.js');
window.setTimeout('some_scripts_function()', 1);

SOLUTION
Avatar of third
third
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial